tolrac / cakephp-5-sweet-alert-helper
SweetAlertHelper plugin for CakePHP
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:cakephp-plugin
Requires
- cakephp/cakephp: ^5.0.1
Requires (Dev)
- cakephp/cakephp-codesniffer: ^5.0
- phpunit/phpunit: ^10.5.5 || ^11.1.3
This package is not auto-updated.
Last update: 2025-08-07 22:04:22 UTC
README
Requirements
- CakePHP 5.x
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require tolrac/cakephp-5-sweet-alert-helper
Usage
In your src/View/AppView.php
, put the helpers
public function initialize()
{
...
$this->loadHelper('SweetAlertHelper.Form');
$this->loadHelper('SweetAlertHelper.Html');
...
}
In your 'src/Application.php', load the plugin in the bootstrap()
method:
public function bootstrap(): void
{
...
$this->addPlugin('SweetAlertHelper');
...
}
and in the template layout (or in the views), load the js file:
<?php
...
echo $this->Html->script('SweetAlertHelper.sweetalert2.min');
...
?>
Then you can use the confirm
option of
postLink
method ofFormHelper
link
method ofHtmlHelper
to show a Sweet Alert at the place of a normal alert, with your message:
<?= $this->Html->link('home',['action'=>'display','home'],['confirm'=>'Etes-vous vraiment sûr ?']); ?>
<?= $this->Form->postLink('home',['action'=>'display','home'],['confirm'=>'Etes-vous vraiment sûr ?']) ?>