Skip to content

Commit

Permalink
Add deleteLink().
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Jan 17, 2025
1 parent ce49692 commit 9b04523
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
23 changes: 12 additions & 11 deletions en/appendices/5-2-migration-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ Behavior Changes
being filterable from logging.
- ``NumericPaginator::paginate()`` now uses the ``finder`` option even when a ``SelectQuery`` instance is passed to it.

New Features
============

- ``Cake\Database\Type\JsonType::setDecodingOptions()`` was added. This method
lets you define the value for the ``$flags`` argument of ``json_decode()``.
- ``CounterCacheBehavior::updateCounterCache()`` was added. This method allows
you to update the counter cache values for all records of the configured
associations. ``CounterCacheCommand`` was also added to do the same through the
console.

Deprecations
============
Expand Down Expand Up @@ -75,11 +66,15 @@ Console
Database
--------

- ``JsonType::setDecodingOptions()`` was added. This method lets you define the
bitmask options used by ``json_encode()`` calls.
- The ``nativeuuid`` type was added. This type enables ``uuid`` columns to be
used in Mysql connections with MariaDB. In all other drivers, ``nativeuuid``
is an alias for ``uuid``.
- ``Cake\Database\Type\JsonType::setDecodingOptions()`` was added. This method
lets you define the value for the ``$flags`` argument of ``json_decode()``.
- ``CounterCacheBehavior::updateCounterCache()`` was added. This method allows
you to update the counter cache values for all records of the configured
associations. ``CounterCacheCommand`` was also added to do the same through the
console.

ORM
---
Expand All @@ -88,6 +83,12 @@ ORM
allows you to update the counter cache values for all records of the configured
associations.

View
----

- ``FormHelper::deleteLink()`` has been added as convenience wrapper for delete links in
templates using `DELETE` method.

Error
-----

Expand Down
7 changes: 4 additions & 3 deletions en/tutorials-and-examples/cms/articles-controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ that allow users to delete articles:
</td>
<td>
<?= $this->Html->link('Edit', ['action' => 'edit', $article->slug]) ?>
<?= $this->Form->postLink(
<?= $this->Form->deleteLink(
'Delete',
['action' => 'delete', $article->slug],
['confirm' => 'Are you sure?'])
Expand All @@ -541,8 +541,9 @@ that allow users to delete articles:
</table>
Using :php:meth:`~Cake\\View\\Helper\\FormHelper::postLink()` will create a link
that uses JavaScript to do a POST request deleting our article.
Using :php:meth:`~Cake\\View\\Helper\\FormHelper::deleteLink()` will create a link
that uses JavaScript to do a DELETE request deleting our article.
Prior to CakePHP 5.2 you need to use ``postLink()`` instead.

.. note::

Expand Down
25 changes: 24 additions & 1 deletion en/views/helpers/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,7 @@ inside opened forms.
Creating POST Links
-------------------

.. php:method:: postLink(string $title, mixed $url = null, array $options = [])
.. php:method:: postLink(string $title, array|string|null $url = null, array $options = [])
* ``$title`` - Mandatory string providing the text to be wrapped in ``<a>``
tags.
Expand Down Expand Up @@ -2170,6 +2170,29 @@ use :php:meth:`\\Cake\\View\\Helper\\FormHelper::button()` or

.. _customizing-templates:

Creating DELETE Links
-------------------

.. php:method:: deleteLink(string $title, array|string|null $url = null, array $options = [])
* ``$title`` - Mandatory string providing the text to be wrapped in ``<a>``
tags.
* ``$url`` - Optional. String or array which contains the URL
of the form (Cake-relative or external URL starting with ``http://``).
* ``$options`` - An optional array including any of the
:ref:`general-control-options`, or of the specific options (see below) as well
as any valid HTML attributes.

Creates an HTML link, but accesses the URL using the method you specify
(defaults to DELETE). Requires JavaScript to be enabled in browser::

// In your template, to delete an article, for example
<?= $this->Form->deleteLink(
'Delete',
['action' => 'delete', $article->id],
['confirm' => 'Are you sure?'])
?>

Customizing the Templates FormHelper Uses
=========================================

Expand Down

0 comments on commit 9b04523

Please sign in to comment.