[英]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:
当运行index.php时,出现以下错误:
Fatal error: [Cake\\View\\Exception\\MissingHelperException] Helper class EasyuiHelper could not be found.
致命错误:[Cake \\ View \\ Exception \\ MissingHelperException]找不到助手类EasyuiHelper。
#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: 我按照以下过程创建了插件:
I created the helper for the plugin in plugins/Easyui/scr/View/Helper EasyuiHelper.php:
我在
plugins/Easyui/scr/View/Helper EasyuiHelper.php:
为插件创建了帮助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()){ // ... } }
I added the following line in config/bootstrap : 我在config / bootstrap中添加了以下行:
Plugin::load('Easyui');
these in View/AppView
: 这些在
View/AppView
:
public function initialize() { parent::initialize(); $this->loadHelper('Easyui.Easyui'); }
and this one in Controller/AppController
: 而这个在
Controller/AppController
:
public $helpers = ['Easyui.Easyui'];
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. 您需要将路径添加到composer.json,以便自动加载器可以将其拾取。 See http://book.cakephp.org/3.0/en/plugins.html#autoloading-plugin-classes
参见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. 我建议您始终阅读整章,而不只是部分摘录。 ;)
;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.