我在 ubuntu 上创建了一个 zend 项目,它位于 /var/www/student/ 目录中。
现在我在这个位置有了 head.phtml 文件:
/student/application/views/scripts/index/head.phtml
当我尝试在
中包含 head.phtml 文件时/student/application/modules/test/views/scripts/all/index.phtml
像这样:
echo $this->partial('index/head.phtml');
它给我以下错误:
Message: script 'index/head.phtml' not found in path (/var/www/student/application/modules/notification/views/scripts/)
包含文件对我来说总是一项困难的工作。如何解决这个问题。我必须将这个文件包含在许多模块中,然后我不应该猜测路径的永久解决方案是什么
谢谢
最佳答案
您可以添加多个路径来查找脚本 View 文件。最好的方法是在所有常用文件(如页眉、页脚、元...)的 Bootstrap 文件中执行此操作。
只需在您的 Bootstrap 中添加一个 setupView 方法,您就可以在其中处理与您的 View 相关的所有内容:
protected function _initView()
{
$view = new Zend_View();
// setup your view with jquery and other stuffs...
// [ ... ]
// add the view directory to the stack of scripts paths
$view->addScriptPath(APPLICATION_PATH . '/views/scripts/');
}
关于php - Zend 中的简单文件包含问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6166470/