【问题标题】:Simple File include problem in Zend?Zend 中的简单文件包含问题?
【发布时间】:2011-09-04 05:16:45
【问题描述】:

我在 /var/www/student/ 目录中的 ubuntu 上创建了一个 zend 项目。

现在我在这个位置有 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/) 

包含文件对我来说始终是一项艰巨的工作。如何解决这个问题。我必须将此文件包含在许多模块中,那么我不应该猜测路径的永久解决方案是什么

谢谢

【问题讨论】:

  • 试试echo $this->partial('all/head.phtml');

标签: php zend-framework ubuntu include-path


【解决方案1】:
<? $this->setScriptPath('/student/application/views/scriptss'); ?>
<?= $this->partial('index/head.phtml') ?>

【讨论】:

    【解决方案2】:

    您可以添加多个路径来查找脚本视图文件。最好的方法是在引导文件中为所有常用文件(如页眉、页脚、元数据...)执行此操作。

    只需在您的引导程序中添加一个 setupView 方法,您可以在其中处理与您的视图相关的所有内容:

    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/');
    }
    

    【讨论】:

    • 克里斯托夫·梅拉:没错。 addScriptPath() 是解决方案。我也发布了我的解决方案。
    【解决方案3】:

    我在 Controller 的 init() 函数中添加了以下行。

    public function init() {
        $this->view->addScriptPath( APPLICATION_PATH . '/views/scripts/' );
    }
    

    在视图中添加 head.phtml 文件,如下所示:

    echo $this->partial('index/head.phtml');
    

    文件添加成功。

    【讨论】:

      猜你喜欢
      • 2011-08-14
      • 2011-06-17
      • 2012-04-13
      • 1970-01-01
      • 2011-01-15
      • 1970-01-01
      • 1970-01-01
      • 2010-10-22
      • 1970-01-01
      相关资源
      最近更新 更多