Zend Framework 使用 html 文件而不是 phtml 作为视图脚本

发布于 2024-12-20 03:04:21 字数 609 浏览 5 评论 0原文

我们有一个开发人员代码,他是用 php 编写的。当我们研究代码时,我们注意到所有视图的扩展名都是html,而不是phtml。我们通过将文件重命名为 phtml 进行检查,结果出现错误。令人惊奇的是,他们没有在应用程序中做到这一点,而是在 Zend Level 中做到了。

如果我用新下载的内容替换库目录中的 zend 框架,应用程序将停止工作。说找不到视图

有谁知道他们是怎么做到的(修改ZF以搜索html而不是phtml文件)?

还有一件事: 他到处都在使用变量 $this->baseURL(不是 zF 提供的 $this->baseUrl())来保存基本 url。它不是一个助手,我检查了,似乎在代码中的任何地方都找不到声明,但仍然神奇的是它可以通过所有控制器和视图使用。他们是如何实施的?我搜索了所有文件,但没有定义 baseURL 或将选项 baseURL 写入 AUTHSTORAGE >,或者任何东西。那么他是如何做到这一点的呢?又修改zf了?

We had a developer code for us, and he did it in php. When we were studying the code, we noticed that all the views have html as their extension instead of phtml. We checked by renaming a file to phtml, and it gives an error. What's amazing is that they have not done this in the app, they have done it at Zend Level.

IF I replace the zend framework in the library directory with a fresh download, the app stops working. saying that the view was not found

Does anyone know how they did this (modified ZF to search for html instead of phtml files)?

One more thing:
all over the place, he's using a variable $this->baseURL (not $this->baseUrl() as provided by zF) which holds the base url. Its not a helper, I checked and can't seem to find the declaration anywhere in the code, but still magically it is available through all the controllers and views. How did they implement? I did a search through all the files, but nowhere is baseURL defined or the option baseURL written to AUTH, STORAGE, or anything. So how did he get to this? Modify the zf again?

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

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

发布评论

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

评论(2

乖乖哒 2024-12-27 03:04:21

他们可能更改了 Zend Layout 类文件 Zend/Layout.php

您可以检查 protected $_viewSuffix = 'html'; 而不是默认的 phtml。

您可以通过将以下内容添加到引导程序来修复此问题,以便升级 Zend Framework 文件。

protected function _initViewSuffix()
{
    Zend_Layout::getMvcInstance()->setViewSuffix('html');
}

至于 $baseURL 变量,这可以通过插件或操作助手来设置。

如果您获得视图对象,您可以执行类似 $view->baseURL = 'xxx'; 的操作来使其可用。这可以通过插件或操作助手来完成。

希望有帮助。

They may have changed the Zend Layout class file Zend/Layout.php.

You can check for protected $_viewSuffix = 'html'; instead of phtml which is the default.

You can fix this by adding the following to your bootstrap so you can upgrade the Zend Framework files.

protected function _initViewSuffix()
{
    Zend_Layout::getMvcInstance()->setViewSuffix('html');
}

As for the $baseURL variable, this could have been set via a plugin, or action helper.

If you get the view object you can do something like $view->baseURL = 'xxx'; to make it available. This can be done from a plugin or action helper.

Hope that helps.

夜声 2024-12-27 03:04:21

看看 Zend/Controller/Action/Helper/ViewRenderer.php ,您应该在其中找到

protected $_viewSuffix = 'html'

更改视图后缀的更好方法是将其添加到 application/Bootstrap.php

/**
 * Set default view suffix to .html (see http://framework.zend.com/issues/browse/ZF-5301)
 */
protected function _initViewSuffix()
{
    Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setViewSuffix('html');
}

或者您可以通过所有控制器中的 init 方法来更改它

public function init()
{
    $this->_helper->viewRenderer->setViewSuffix('html');
}

Zend_Layout 正如 drew010 所提到的,仅更改布局的后缀,而不更改视图的后缀。

Have a look at Zend/Controller/Action/Helper/ViewRenderer.php where you should find

protected $_viewSuffix = 'html'

Better ways to change the view suffix is adding this to the application/Bootstrap.php

/**
 * Set default view suffix to .html (see http://framework.zend.com/issues/browse/ZF-5301)
 */
protected function _initViewSuffix()
{
    Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setViewSuffix('html');
}

Or you can change it by this init method in all controllers

public function init()
{
    $this->_helper->viewRenderer->setViewSuffix('html');
}

Zend_Layout as mentioned by drew010 only changes the suffix of layouts and not of views.

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