mirko-pagliai / cakephp-essentials
cakephp-essentials
Installs: 3 348
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:cakephp-plugin
pkg:composer/mirko-pagliai/cakephp-essentials
Requires
- php: >=8.4
- axllent/jquery: ~3.7
- cakephp/cakephp: ^5.2
- friendsofcake/bootstrap-ui: ^5.1.1
- symfony/filesystem: ^7.3
- twbs/bootstrap: ~5.3
- twbs/bootstrap-icons: ^1.11
Requires (Dev)
- cakedc/cakephp-phpstan: ^4.0
- cakephp/authentication: ^3.2
- cakephp/authorization: ^3.0
- cakephp/cakephp-codesniffer: ^5.0
- mockery/mockery: ^1.6
- phpunit/phpunit: ^11.2.7
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": [
"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",
]
},
Or run the commands directly in the shell:
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
It can also be useful to launch the command:
bin/cake plugin assets symlink -q --overwrite
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'); } }
Add some basic assets to the layout
You can consider adding some key assets to your layout, depending on your needs:
Css:
echo $this->fetch('css'); echo $this->Html->css('/vendor/bootstrap/css/bootstrap.min.css'); echo $this->Html->css('/vendor/bootstrap-icons/bootstrap-icons.min.css');
Scripts:
echo $this->fetch('script'); echo $this->Html->script('/vendor/jquery/jquery.min.js'); echo $this->Html->script('/vendor/bootstrap/js/bootstrap.min.js'); echo $this->Html->script('/cake/essentials/js/collapsible-toggle-icon.min.js');
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.jswhich contains Popper; - you will need to initialize both, as indicated in the documentation.
You can includewebroot/js/enable-popovers.min.jsandwebroot/js/enable-tooltips.min.jsfiles 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');