php – Zend Framework:如何在模块化应用程序中设置布局目录?
作者:互联网
我想要实现的目录结构是这样的:
application/default/views/layouts/layout.phtml
application/default/views/scripts/index/index.phtml
application/admin/views/layouts/layout.phtml
application/admin/views/scripts/index/index.phtml
library/Zend
config/config.ini
public/index.php (bootstrap)
但我无法弄清楚如何让Zend在我的每个模块中找到我的layout.phtml.
在我的引导中,我有:
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application/'));
define('APPLICATION_ENVIRONMENT', 'testing');
//setup path to our library files
set_include_path( APPLICATION_PATH . '/../library' . PATH_SEPARATOR .
get_include_path() );
//register the autoloader
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
//set config in the registry
$config = new Zend_Config_Ini( APPLICATION_PATH . '/../config/config.ini', APPLICATION_ENVIRONMENT );
Zend_Registry::set('config', $config);
//setup logging
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../log/debug.log');
$logger = new Zend_Log($writer);
Zend_Registry::set('logger', $logger);
//run!
$frontController = Zend_Controller_Front::getInstance();
$frontController->addModuleDirectory(APPLICATION_PATH);
//initialize Zend_Layout's MVC helpers
Zend_Layout::startMvc();
$frontController->throwExceptions(true);
try {
Zend_Controller_Front::getInstance()->dispatch();
} catch (Exception $exception) {
echo '<html><body><center>' . 'An exception occured while dispatching the front controller.';
if (defined('APPLICATION_ENVIRONMENT') && APPLICATION_ENVIRONMENT != 'production' ) {
echo '<br /><br />' . $exception->getMessage() . '<br />' . '<div align="left">Stack Trace:' . '<pre>' . $exception->getTraceAsString() . '</pre></div>';
}
echo '</center></body></html>';
exit(1);
}
我哪里错了?
更新:
我很久没有看过这个,所以接受的解决方案可能不是最新的.如果有人想发布这个问题的最新解决方案(即ZF 1.8),请这样做!对于正在寻找解决方案的其他人来说,这将是有帮助的.
解决方法:
您应该查看Per Module Zend_Layout,在本文中,作者将准确介绍您要实现的目标.他的方法是为前控制器编写一个处理布局注册的插件.
标签:php,zend-framework,bootstrapping 来源: https://codeday.me/bug/20190827/1743976.html