简体   繁体   中英

CakePHP 3.1 - missing helper error for plugin

I created a plugin, but didnt baked it, that basicly has a helper which I want to use in the application. When running the index.php I get the following error:

Fatal error: [Cake\\View\\Exception\\MissingHelperException] Helper class EasyuiHelper could not be found.

  #0 C:\\xampp\\htdocs\\myKMG_3\\vendor\\cakephp\\cakephp\\src\\Core\\ObjectRegistry.php(91): Cake\\View\\HelperRegistry->_throwMissingClassError('Easyui', 'Easyui') #1 C:\\xampp\\htdocs\\myKMG_3\\vendor\\cakephp\\cakephp\\src\\View\\View.php(1001): Cake\\Core\\ObjectRegistry->load('Easyui.Easyui', Array) #2 C:\\xampp\\htdocs\\myKMG_3\\src\\View\\AppView.php(40): Cake\\View\\View->loadHelper('Easyui.Easyui') #3 C:\\xampp\\htdocs\\myKMG_3\\vendor\\cakephp\\cakephp\\src\\View\\View.php(335): App\\View\\AppView->initialize() #4 C:\\xampp\\htdocs\\myKMG_3\\vendor\\cakephp\\cakephp\\src\\View\\ViewBuilder.php(350): Cake\\View\\View->__construct(Object(Cake\\Network\\Request), Object(Cake\\Network\\Response), Object(Cake\\Event\\EventManager), Array) #5 C:\\xampp\\htdocs\\myKMG_3\\vendor\\cakephp\\cakephp\\src\\View\\ViewVarsTrait.php(119): Cake\\View\\ViewBuilder->build(Array, Object(Cake\\Network\\Request), Object(Cake\\Network\\Response), Object(Cake\\Event\\EventManager)) #6 C:\\xampp\\htdocs\\myKMG_ in C:\\xampp\\htdocs\\myKMG_3\\vendor\\cakephp\\cakephp\\src\\Error\\ErrorHandler.php on line 156 

I followed this procedure to create the plugin:

  1. I created the plugin structure described by the cookbook in: http://book.cakephp.org/3.0/en/plugins.html#creating-your-own-plugins
  2. I created the helper for the plugin in plugins/Easyui/scr/View/Helper EasyuiHelper.php:

     namespace Easyui\\View\\Helper; use Cake\\View\\Helper; class EasyuiHelper extends Helper { public function linkButton($id_image='imgLinkButton', $optionsImg=array()){ // ... } } 
  3. I added the following line in config/bootstrap :

     Plugin::load('Easyui'); 

    these in View/AppView :

     public function initialize() { parent::initialize(); $this->loadHelper('Easyui.Easyui'); } 

    and this one in Controller/AppController :

     public $helpers = ['Easyui.Easyui']; 
  4. I use the helper in default layout file:

     $this->Easyui->linkButton('imgPrint', array('iconCls'=>'icon-print', 'onClick'=>'window.print()')); 

Where did I go wrong? Did I miss anything?

You need to add the path to your composer.json so that the autoloader can pick them up. See http://book.cakephp.org/3.0/en/plugins.html#autoloading-plugin-classes

"autoload": {
    "psr-4": {
        "Easyui\\": "./plugins/Easyui/src",
    }
},
"autoload-dev": {
    "psr-4": {
        "Easyui\\Test\\": "./plugins/Easyui/tests",
    }
}

I recommend you to always read the whole chapter and not only partial excerpts of it. ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM