Zend 框架控制器动作助手
添加操作助手类后出现致命错误。我正在尝试加载与调用的布局相对应的布局。以下是我的代码片段:
首先,我在 application/controller/helpers 下添加了一个帮助器类:
class Zend_Controller_Action_Helper_Layout extends Zend_Controller_Action_Helper_Abstract {
public $pluginLoader;
public function __construct()
{
// TODO Auto-generated Constructor
$this->pluginLoader = new Zend_Loader_PluginLoader ();
}
public function preDispatch()
{
$bootstrap = $this->getActionController()->getInvokeArg('bootstrap');
$config = $bootstrap->getOptions();
$module = $this->getRequest()->getModuleName();
if (isset($config[$module]['resources']['layout']['layout'])) {
$layoutScript = $config[$module]['resources']['layout']['layout'];
$this->getActionController()->getHelper('layout')->setLayout($layoutScript);
}
}
}
然后我在 bootstrap.php 中添加了一个加载器:
protected function _initLayoutHelper() {
$this->bootstrap('frontController');
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH .'/controllers/helpers');
$layout = Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_Layout());
}
以下是我的 application.ini:
[production]
autoloaderNamespaces.tree = "Tree_"
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.helperDirectory = APPLICATION_PATH "/controllers/helpers"
resources.modules[] = ""
contact.resources.frontController.defaultControllerName = "index"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout = layout
admin.resources.layout.layout = admin
#admin.resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.view[] =
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
运行此代码时,我收到以下错误:
警告: 包括(Zend\Controller\Action\Helper\LayoutLoader.php) [function.include]:打开失败 流:没有这样的文件或目录 D:\个人\proj\renovate\library\Zend\Loader.php 第83行
警告:include() [函数.include]: 打开失败 'Zend\Controller\Action\Helper\LayoutLoader.php' 纳入 (include_path='D:\personal\proj\renovate\application/../library;D:\personal\proj\renovate\library;.;C:\php5\pear') 在 D:\个人\proj\renovate\library\Zend\Loader.php 第83行
致命错误:类 'Zend_Controller_Action_Helper_LayoutLoader' 未找到于 D:\个人\proj\renovate\application\Bootstrap.php 第 33 行
,请告诉我,我该如何解决这个问题。我是 Zend 框架的初学者。
I am getting fatal error after adding the action helper class. I am trying to load layout corresponding to called layout. Following is my code snippet:
First of all i added a helper class under application/controller/helpers:
class Zend_Controller_Action_Helper_Layout extends Zend_Controller_Action_Helper_Abstract {
public $pluginLoader;
public function __construct()
{
// TODO Auto-generated Constructor
$this->pluginLoader = new Zend_Loader_PluginLoader ();
}
public function preDispatch()
{
$bootstrap = $this->getActionController()->getInvokeArg('bootstrap');
$config = $bootstrap->getOptions();
$module = $this->getRequest()->getModuleName();
if (isset($config[$module]['resources']['layout']['layout'])) {
$layoutScript = $config[$module]['resources']['layout']['layout'];
$this->getActionController()->getHelper('layout')->setLayout($layoutScript);
}
}
}
Then i added a loader in bootstrap.php:
protected function _initLayoutHelper() {
$this->bootstrap('frontController');
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH .'/controllers/helpers');
$layout = Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_Layout());
}
Following is my application.ini:
[production]
autoloaderNamespaces.tree = "Tree_"
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.helperDirectory = APPLICATION_PATH "/controllers/helpers"
resources.modules[] = ""
contact.resources.frontController.defaultControllerName = "index"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout = layout
admin.resources.layout.layout = admin
#admin.resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.view[] =
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
While running this code i am getting following errors:
Warning:
include(Zend\Controller\Action\Helper\LayoutLoader.php)
[function.include]: failed to open
stream: No such file or directory in
D:\personal\proj\renovate\library\Zend\Loader.php
on line 83Warning: include() [function.include]:
Failed opening
'Zend\Controller\Action\Helper\LayoutLoader.php'
for inclusion
(include_path='D:\personal\proj\renovate\application/../library;D:\personal\proj\renovate\library;.;C:\php5\pear')
in
D:\personal\proj\renovate\library\Zend\Loader.php
on line 83Fatal error: Class
'Zend_Controller_Action_Helper_LayoutLoader'
not found in
D:\personal\proj\renovate\application\Bootstrap.php
on line 33
Kindly let me know, how can i come out from this issue. I am beginner in Zend Framework.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎您的
include_path
无效请尝试将其插入到 index.php 中:
这适用于如下目录结构:
Seems like you have invalid
include_path
Try insert this in the index.php:
This works for directory structure like:
我认为包含路径是有效的。以下是我的index.php
定义应用程序目录的路径
定义应用程序环境
确保
library/
位于include_path
上I think include path is valid. Following is my index.php
Define path to application directory
Define application environment
Ensure
library/
is oninclude_path