CakePHP3 Plugin cell is missing

649 views Asked by At

My Process

  1. make plugin cell

    $ bin/cake bake plugin Abc
    
    $ bin/cake bake cell Abc.New
    

upper process make 3 files

    plugins/Abc/src/View/Cell/NewCell.php

    plugins/Abc/src/Template/Cell/Menu/display.php

and test file.

  1. insert layout/default.ctp next code

     <?php $cell = $this->cell('Abc.New'); ?>
    
  2. error

Cell class Abc.New is missing.

Cake\View\Exception\MissingCellException

I can't find solution. please help me!!

1

There are 1 answers

0
arajcany On

Post is a bit old but in case someone else stumbles on this thread...

Cells rely on Namespaces to load and render the correct [cell].ctp file. In other words, even though you have done the required Plugin::loadAll(); in your bootstrap.php file, you still need to modify the composer.json file and add the Plugin. For example, my Plugin is called 'Metronic', notice the extra 2 lines in autoload and autolaod-dev

  "autoload": {
    "psr-4": {
      "App\\": "src",
      "Metronic\\": "./plugins/Metronic/src"
    }
  },
  "autoload-dev": {
    "psr-4": {
      "App\\Test\\": "tests",
      "Cake\\Test\\": "./vendor/cakephp/cakephp/tests",
      "Metronic\\Test\\": "./plugins/Metronic/tests"
    }
  },

See CakePHP manual here http://book.cakephp.org/3.0/en/plugins.html#autoloading-plugin-classes.

My suggestions is that you use the Bake command to create Plugins in the future. The manual does not explicitly say this, but this is what happens when you use the Bake command:

  • It creates the basic directory structure for the Plugin
  • It inserts a line in bootstrap.php e.g.Plugin::load('Metronic', ['bootstrap' => false, 'routes' => true]);
  • It inserts 2 lines in the composer.json file (as per my example above)

The only thing you need to then do is tell Composer to refresh its autoloading cache

$ bin\cake bake plugin Metronic
$ php composer.phar dumpautoload

Hope this helps..