mirko-pagliai / cakephp-essentials
cakephp-essentials
Installs: 33
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:cakephp-plugin
Requires
- php: >=8.4
- axllent/jquery: ~3.7
- cakephp/cakephp: ^5.0
- friendsofcake/bootstrap-ui: ^5.1
- moment/moment: ^2.30
- twbs/bootstrap: ~5.3
- twbs/bootstrap-icons: ^1.11
Requires (Dev)
- cakedc/cakephp-phpstan: ^4.0
- cakephp/cakephp-codesniffer: ^5.0
- phpunit/phpunit: ^11.1.3
- vimeo/psalm: ^6.9
This package is auto-updated.
Last update: 2025-04-03 11:05:11 UTC
README
Various classes and utilities useful for various CakePHP projects.
Creates links to assets
In your composer.json
, add the post-update-cmd
command event:
"scripts": {
"post-update-cmd": [
"bin/cake plugin assets symlink -q --overwrite",
"rm -rf webroot/vendor/ && mkdir webroot/vendor/ -p",
"ln -s ../../vendor/twbs/bootstrap/dist/ webroot/vendor/bootstrap -f",
"ln -s ../../vendor/twbs/bootstrap-icons/font/ webroot/vendor/bootstrap-icons -f",
"ln -s ../../vendor/axllent/jquery/ webroot/vendor/jquery -f",
"ln -s ../../vendor/moment/moment/min/ webroot/vendor/moment -f"
]
},
Or run the commands directly in the shell:
bin/cake plugin assets symlink -q --overwrite mkdir webroot/vendor/ -p ln -s ../../vendor/twbs/bootstrap/dist/ webroot/vendor/bootstrap -f ln -s ../../vendor/twbs/bootstrap-icons/font/ webroot/vendor/bootstrap-icons -f ln -s ../../vendor/axllent/jquery/ webroot/vendor/jquery -f ln -s ../../vendor/moment/moment/min/ webroot/vendor/moment -f
Extends the View
use Cake\Essentials\View\View; class AppView extends View { }
If necessary, you can rewrite the default helpers by implementing the initialize()
method and calling
parent::initialize()
before adding your own helpers.
class AppView extends View public function initialize(): void { parent::initialize(); /** * These override any helpers defined by the parent. */ $this->addHelper('Html'); $this->addHelper('Form'); } }
Using Tooltips and Popovers
Several helper methods support tooltips and popovers and can generate them automatically.
Please refer to the Bootstrap documentation before using them (here and here).
Keep in mind that:
- both depend on the third-party library Popper, which you need to include, or you can use
bootstrap.bundle.min.js
which contains Popper; - you will need to initialize both, as indicated in the documentation.
You can includewebroot/js/enable-popovers.min.js
andwebroot/js/enable-tooltips.min.js
files in yourt layout, which will do it automatically:
echo $this->Html->script('/cake/essentials/js/enable-popovers.min.js'); echo $this->Html->script('/cake/essentials/js/enable-tooltips.min.js');
How to use Bake templates
In your config/bootstrap.php
file:
Configure::write('Bake.theme', 'Cake/Essentials');
Or you can use the --theme
option (or --t
) with Cake/Essentials
value.
Example:
bin/cake bake template ServiceStops -t Cake/Essentials -f
See also CakePHP Bake 2.x Cookbook.
Sets the default locale date and time format
For example, in your bootstrap.php
:
/** * Sets the default locale date and time format. * * @see https://book.cakephp.org/5/en/core-libraries/time.html#setting-the-default-locale-and-format-string * @see https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax */ Date::setToStringFormat('dd/MM/yyyy'); DateTime::setToStringFormat('dd/MM/yyyy HH:mm');