添加动作帮助程序类后,我遇到致命错误。我正在尝试加载与被调用布局相对应的布局。以下是我的代码段:
首先,我在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的\控制器\动作\助手\ LayoutLoader.php) [function.include]:无法打开 stream:没有这样的文件或目录 d:\个人\凸出\翻盖\库\ Zend的\ Loader.php 在第83行
警告:include()[function.include]: 打开失败 'Zend的\控制器\行动\辅助\ LayoutLoader.php' 包括在内 (include_path中= 'd:\个人\凸出\翻盖\应用/../文库; d:\个人\凸出\翻盖\库; C:\ PHP5 \梨') 在 d:\个人\凸出\翻盖\库\ Zend的\ Loader.php 在第83行
致命错误:类 'Zend_Controller_Action_Helper_LayoutLoader' 找不到 d:\个人\凸出\翻盖\程序\ bootstrap.php中 在第33行
请告诉我,我怎么能从这个问题出来。我是Zend Framework的初学者。
答案 0 :(得分:0)
好像你有无效的include_path
尝试在index.php中插入此内容:
define('ROOTDIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
define('LIBDIR', realpath(ROOTDIR . '../library') . DIRECTORY_SEPARATOR);
set_include_path(implode(PATH_SEPARATOR, array_merge(explode(PATH_SEPARATOR,ini_get('include_path')), array(LIBDIR))));
这适用于目录结构,如:
application/ library/ - Zend/ httpdocs/ - index.php
答案 1 :(得分:0)
我认为包含路径是有效的。以下是我的index.php
定义应用程序目录的路径
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
定义应用程序环境
defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));
确保library/
include_path
set_include_path(implode(PATH_SEPARATOR, array(realpath(APPLICATION_PATH . '/../library'),get_include_path(),)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$application->bootstrap()->run();