dongwh1992 2015-10-23 07:24
浏览 62
已采纳

CakePHP 3.1 - 插件缺少帮助程序错误

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?

  • 写回答

1条回答 默认 最新

  • douzi2785 2015-10-23 12:12
    关注

    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. ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档