CakePHP 3 - Best Practice and Cookbook

Next: CakePHP 3: Use Middleware to support REDIS Cache UP: TOC

Creating a Plugin for CakePHP 3 can easily be done using the Bake Command. This is how it works:

bin/cake bake plugin WnkCakephp3ImagesAdmin Welcome to CakePHP v3.3.13 Console --------------------------------------------------------------- App : src Path: /.../cakephp3/src/ PHP : 7.0.15 --------------------------------------------------------------- Plugin Name: WnkCakephp3ImagesAdmin Plugin Directory: /.../cakephp3/plugins/WnkCakephp3ImagesAdmin --------------------------------------------------------------- Look okay? (y/n/q) [y] > y Generating README.md file... Creating file /u.../cakephp3/plugins/WnkCakephp3ImagesAdmin/README.md Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/README.md` Generating composer.json file... Creating file /.../cakephp3/plugins/WnkCakephp3ImagesAdmin/composer.json Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/composer.json` Generating config/routes.php file... Creating file /.../cakephp3/plugins/WnkCakephp3ImagesAdmin/config/routes.php Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/config/routes.php` Generating phpunit.xml.dist file... Creating file /..../cakephp3/plugins/WnkCakephp3ImagesAdmin/phpunit.xml.dist Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/phpunit.xml.dist` Generating src/Controller/AppController.php file... Creating file /.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Controller/AppController.php Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Controller/AppController.php` Generating webroot/empty file... Creating file /.../cakephp3/plugins/WnkCakephp3ImagesAdmin/webroot/empty Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/webroot/empty` Modifying composer autoloader File `/.../cakephp3/composer.json` exists Do you want to overwrite? (y/n/a/q) [n] > a Wrote `/.../41share/cakephp3/composer.json` /.../cakephp3/config/bootstrap.php modified --------------------------------------------------------------- Created: WnkCakephp3ImagesAdmin in /.../cakephp3/plugins/WnkCakephp3ImagesAdmin #

Next we we will bake the model based on an existing database table "Wnk_images".

bin/cake bake model --plugin WnkCakephp3ImagesAdmin WnkImages Welcome to CakePHP v3.3.13 Console --------------------------------------------------------------- App : src Path: /.../cakephp3/src/ PHP : 7.0.15 --------------------------------------------------------------- One moment while associations are detected. Baking table class for WnkImages... Creating file /.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Model/Table/WnkImagesTable.php Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Model/Table/WnkImagesTable.php` Baking entity class for WnkImage... Creating file /.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Model/Entity/WnkImage.php Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Model/Entity/WnkImage.php` Baking test fixture for WnkImages... Creating file /.../cakephp3/plugins/WnkCakephp3ImagesAdmin/tests/Fixture/WnkImagesFixture.php Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/tests/Fixture/WnkImagesFixture.php` Bake is detecting possible fixtures... Baking test case for WnkCakephp3ImagesAdmin\Model\Table\WnkImagesTable ... Creating file /.../cakephp3/plugins/WnkCakephp3ImagesAdmin/tests/TestCase/Model/Table/WnkImagesTableTest.php Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/tests/TestCase/Model/Table/WnkImagesTableTest.php` bin/cake bake controller --plugin WnkCakephp3ImagesAdmin WnkImages Welcome to CakePHP v3.3.13 Console --------------------------------------------------------------- App : src Path: /.../cakephp3/src/ PHP : 7.0.15 --------------------------------------------------------------- Baking controller class for WnkImages... Creating file /.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Controller/WnkImagesController.php Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Controller/WnkImagesController.php` Bake is detecting possible fixtures... Baking test case for WnkCakephp3ImagesAdmin\Controller\WnkImagesController ... Creating file /.../cakephp3/plugins/WnkCakephp3ImagesAdmin/tests/TestCase/Controller/WnkImagesControllerTest.php Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/tests/TestCase/Controller/WnkImagesControllerTest.php` bin/cake bake template --plugin WnkCakephp3ImagesAdmin WnkImages Welcome to CakePHP v3.3.13 Console --------------------------------------------------------------- App : src Path: /.../cakephp3/src/ PHP : 7.0.15 --------------------------------------------------------------- Baking `index` view template file... Creating file /.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Template/WnkImages/index.ctp Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Template/WnkImages/index.ctp` Baking `view` view template file... Creating file /.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Template/WnkImages/view.ctp Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Template/WnkImages/view.ctp` Baking `add` view template file... Creating file /.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Template/WnkImages/add.ctp Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Template/WnkImages/add.ctp` Baking `edit` view template file... Creating file /.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Template/WnkImages/edit.ctp Wrote `/.../cakephp3/plugins/WnkCakephp3ImagesAdmin/src/Template/WnkImages/edit.ctp` Next: CakePHP 3: Use Middleware to support REDIS Cache UP: TOC