php - Zend 中的简单文件包含问题?

标签 php zend-framework ubuntu include-path

我在 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/

相关文章:

php - strtotime 和 date 输出不正确

php - 在哪里使用 Zend_Auth,在模型或 Controller 中?

php - PDOStatement->在生产服务器上执行比在开发服务器上慢 14 倍

python - Xvfb 和 Selenium 临时文件不会自动从/tmp (Ubuntu) 中删除

ubuntu - Mosquitto Broker 上 Ubuntu 密码文件错误

php - 如何在不同类型之间的一个模型中设置一对多关系

php - MySQL 更新语句无法正常工作

php - Zend Framework 中的自定义类和函数

ubuntu - 如何从终端在 ubuntu 上启动 IntelliJ

php - 无法从数据库获取下拉值