How to create new cakephp 3 plugin?

Hi,

Anyone can guide me to create new cakephp 3 plugin?

Thanks.

Follow the docs https://book.cakephp.org/3.0/en/plugins.html#creating-your-own-plugins

You can create plugin by specially two way.

  • Using cakebake

  • Creating plugin structure

For Cakebake you just need to run this code by you terminal “bin/cake bake plugin YourPluginName”.
It will do lots of work automatic like make the plugin sturcture , activate the plugin by changing on .phar file. In one word you don’t need to do any thing in your coding you just get a ready made plugin for use.

But if you want to make plugin by your own then you have to follow these process.

  1. Make this folder structure outside src.

     /src
     /plugins
      /ContactManager
             /config
             /src
                 /Controller
                     /Component
                 /Model
                     /Table
                     /Entity
                     /Behavior
                 /View
                     /Helper
                 /Template
                     /Layout
             /tests
                 /TestCase
                 /Fixture
             /webroot
    
  2. Change into config/bootstrap.php file

Plugin::load('YourPluginName', ['routes' => true]);

OR

Plugin::loadAll(['routes' => true]);

  1. Chnage into plugins/YourPluginName/config/routes.php:.

<?php

use Cake\Routing\Route\DashedRoute;
use Cake\Routing\Router;

Router::plugin(
    'YourPluginName',
    ['path' => '/your-plugin-name'],
    function ($routes) {
        $routes->fallbacks(DashedRoute::class);
    }
);

It’s ready… :slight_smile: Now to access this plugin go to this link
// Access the index route of a plugin controller.
/your-plugin-name/contacts

// Any action on a plugin controller.
/your-plugin-name/contacts/view/1

thanks for your reply.

1 Like