Zend framework Zf1/Zwig/Twig集成失败
我在将Twig和Zend Framework 1与Zwig库alb/Zwig集成时遇到问题Zend framework Zf1/Zwig/Twig集成失败,zend-framework,twig,Zend Framework,Twig,我在将Twig和Zend Framework 1与Zwig库alb/Zwig集成时遇到问题 class Login_IndexController extends Zend_Controller_Action { public function init() { /* Initialize action controller here */ } public function indexAction() { // ac
版本是 alb/zwig版本1.0.1 细枝/细枝1.14.2 zf1 1.12.3 结果是:class Login_IndexController extends Zend_Controller_Action { public function init() { /* Initialize action controller here */ } public function indexAction() { // action body $this->view->toto = "texte"; } }
- 模块控制器动作调用正常
- layout.twig正确显示(parent()工作)
- 不显示index.twig特定的块内容
twig.templateDir = APPLICATION_PATH "/modules/%module%/views/scripts/"
;twig.options.cache = APPLICATION_PATH "/../cache/twig"
autoloaderNamespaces[] = "Twig_"
autoloaderNamespaces[] = "Zwig_"
autoloaderNamespaces[] = "ZFDebug_"
resources.modules[] = ""
resources.layout.layoutPath = APPLICATION_PATH "/modules/Layout/views/scripts/"
resources.layout.layout = "layout"
应用程序/Bootstrap.php
public function _initLayout() {
$layout = $this->getPluginResource("layout")->getLayout();
$layout->setViewSuffix("twig");
}
protected function _initTwig() {
Twig_Autoloader::register();
$config = Zend_Registry::get('config');
$templatePath = array();
$view = new Zwig_View(array(
'encoding' => 'UTF-8',
'helperPath' => array(
),
));
$loader = new Twig_Loader_Filesystem();
$d = new DirectoryIterator($config->resources->frontController->moduleDirectory);
foreach ($d as $fileInfo) {
zif (!$fileInfo->isDot() && $fileInfo->isDir()) {
$moduleName = $fileInfo->getFilename();
$templatePath =
str_replace(
'%module%', $moduleName, $config->twig->templateDir
);
$loader->addPath($templatePath, strtolower($moduleName));
}
}
$zwig = new Zwig_Environment($view, $loader, array(
'debug' => true,
'cache' => APPLICATION_PATH . '/cache/twig/',
//'auto_reload' => true,
));
$view->setEngine($zwig);
$view->doctype(Zend_View_Helper_Doctype::XHTML1_STRICT);
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view, array(
'viewSuffix' => 'twig',
));
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
return $view;
}
应用程序/modules/Login/controllers/IndexController.php
应用程序/模块/布局/视图/脚本/布局.twig
子模板
$this->getHelper('viewRenderer')->setViewSuffix('twig');
您是否更改了默认视图后缀
/*
public function _initLayout() {
$layout = $this->getPluginResource("layout")->getLayout();
$layout->setViewSuffix("twig");
}
*/
这也应该可以从配置文件中进行设置。我在application/Bootstrap.php中发现了问题,必须删除initLayout()函数和application.ini相关的conf。这与细枝继承冲突 application/Booststrap.php
;resources.layout.layoutPath = APPLICATION_PATH "/modules/Layout/views/scripts/"
;resources.layout.layout = "layout"
application.ini
twig.templateDir = APPLICATION_PATH "/modules/%module%/views/scripts/"
;twig.options.cache = APPLICATION_PATH "/../cache/twig"
autoloaderNamespaces[] = "Twig_"
autoloaderNamespaces[] = "Zwig_"
autoloaderNamespaces[] = "ZFDebug_"
resources.modules[] = ""
resources.layout.layoutPath = APPLICATION_PATH "/modules/Layout/views/scripts/"
resources.layout.layout = "layout"
它位于application/Bootstrap.php中的_initTwig和_initLayout方法中。我应该得到一个“找不到文件模板”,对吗?是的,也许你应该得到那个错误。对不起,我没有;我不知道那会是什么问题。你检查过错误日志了吗?这不是扩展的问题,它在源代码中提供了两次。我用xdebug进行了调查,没有发现问题螺母扩展是正确的,似乎子tmeplate没有以我现在不理解的方式呈现,深入研究了twig/zwig代码……web服务器用户有权读取模板文件吗?
;resources.layout.layoutPath = APPLICATION_PATH "/modules/Layout/views/scripts/"
;resources.layout.layout = "layout"