zend-framework - zend view render如何解析查看脚本的路径

标签 zend-framework zend-view context-switch

像“customSearchAction()”这样的操作如何映射到 View 脚本文件名。

这些文件名都不起作用“customsearch.xml.phtml”、“customSearch.xml.phtml”、“custom-search.xml.phtml”。

请注意,我正在使用 xml、json 的上下文切换 View 助手。此外,模块和操作正在正确解析。当我将操作名称更改为“customsearchAction()”并将脚本文件重命名为“customsearch.xml.phtml”时,它就可以工作了。

那么上述情况下 View 脚本文件名是如何解析的呢?在 Zend 框架中

最佳答案

来自documentation :

Note: Naming Conventions: Word Delimiters in Controller and Action Names If your controller or action name is composed of several words, the dispatcher requires that these are separated on the URL by specific path and word delimiter characters. The ViewRenderer replaces any path delimiter found in the controller name with an actual path delimiter ('/'), and any word delimiter found with a dash ('-') when creating paths. Thus, a call to the action /foo.bar/baz.bat would dispatch to FooBarController::bazBatAction() in FooBarController.php, which would render foo-bar/baz-bat.phtml; a call to the action /bar_baz/baz-bat would dispatch to Bar_BazController::bazBatAction() in Bar/BazController.php (note the path separation) and render bar/baz/baz-bat.phtml. Note that the in the second example, the module is still the default module, but that, because of the existence of a path separator, the controller receives the name Bar_BazController, in Bar/BazController.php. The ViewRenderer mimics the controller directory hierarchy.

因此,custom-search.phtml 是正确的名称。现在您可能存储它的目录有误, Controller 名称(和模块)是什么?还要检查一下脚本是否可以被 apache 读取。

编辑

对于 ContextSwitch 使用情况:

  • 初始化为:$contextSwitch->addActionContext('custom-search', 'xml');
  • View 脚本是custom-search.xml.phtml

刚刚在 ZF 1.6 上测试过(旧但应该仍然有效)。所以也许你的初始化是错误的(使用'customSearch'而不是'custom-search'?)。

关于zend-framework - zend view render如何解析查看脚本的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6670049/

相关文章:

oop - 这是一个贫血的领域模型吗?

zend-framework - 向 Zend 表单元素附加或预置 HTML 标签

php - 如何正确创建 Zend Feed?

zend-view - Zend View 在另一个 View 中

php - 使用 Zend Framework 相对于 CodeIgniter 的优势

zend-framework2 - 如何从Zend Framework 2(zf2)中的View访问应用程序配置?

c# - 同时运行两个函数

security - 上下文切换到安全模式的成本是多少(arm trustzone)

multithreading - 双CPU机器上的线程合作