Various classes and utilities useful for various CakePHP projects.
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 -fIt can also be useful to launch the command:
bin/cake plugin assets symlink -q --overwriteuse 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');
}
}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');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');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 -fSee also CakePHP Bake 2.x Cookbook.
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');