Code Generation with Cakephp - Creating Plugin


How to create Plugin in CakePhp using command line?


I assume you already have set up code generation with cakephp, if not see our post about `code generation with cakephp`. Using cmd prompt it quite simple.

Step 1: Type this command

cake bake plugin admin

Step 2: Create Model
 cake bake model plugin --admin (note: admin is plugin name in camelcase)

It will show list of available models, select you want to bake like user model, news model etc.

Note: For cakephp 3+ versions you need to use
cake bake model --plugin PluginName ModelName

Step 3: Create Controller
cake bake controller plugin -- admin

It will show list of available controllers, select you want to bake like user controller, news controller etc



Note: For cakephp 3+ versions you need to use 
cake bake controller --plugin PluginName ControllerName

Step 4: create finally view files for your plugin
cake bake view plugin --admin



Note: For cakephp 3+ versions you need to use 
cake bake template --plugin PluginName TableName

It will show list of available controllers for which you want to make view files, select and done!

Your plugin is ready now.

You can check your plugin at www.yoursite.com/pluginname/controller/action

Post a Comment