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

发布于 2024-11-11 03:55:18 字数 668 浏览 2 评论 0原文

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

现在我在这个位置有 head.phtml 文件:

/student/application/views/scripts/index/head.phtml

当我尝试

/student/application/modules/test/views/scripts/all/index.phtml

像这样包含 head.phtml 文件时:

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

它给了我以下错误:

Message: script 'index/head.phtml' not found in path (/var/www/student/application/modules/notification/views/scripts/) 

包含文件始终是一个困难为我工作。如何解决这个问题。我必须在许多模块中包含这个文件,那么什么是永久解决方案,我不应该猜测路径

谢谢

I have created a zend project on ubuntu which is in /var/www/student/ directory.

Now I have head.phtml file in this location:

/student/application/views/scripts/index/head.phtml

When I try to include head.phtml file in

/student/application/modules/test/views/scripts/all/index.phtml

Like this:

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

It gives me following error:

Message: script 'index/head.phtml' not found in path (/var/www/student/application/modules/notification/views/scripts/) 

Including files is always a difficult job for me. How to fix this. I have to include this file in many modules then what is permanent solution for this that I should not guess the path

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

素手挽清风 2024-11-18 03:55:18

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

只需在引导程序中添加一个 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/');
}

You can add several path to look for script view files. The best way is to do it in the bootstrap file for all your common files (like head, footer, metas...).

Just add a setupView method in your bootstrap where you deal with everything which is realted to your views :

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/');
}
情深缘浅 2024-11-18 03:55:18
<? $this->setScriptPath('/student/application/views/scriptss'); ?>
<?= $this->partial('index/head.phtml') ?>
<? $this->setScriptPath('/student/application/views/scriptss'); ?>
<?= $this->partial('index/head.phtml') ?>
梦太阳 2024-11-18 03:55:18

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

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

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

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

文件已成功添加。

I added following line in Controller's init() function.

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

Add head.phtml file in view like this:

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

File is successfully added.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文