【发布时间】:2014-01-08 10:42:13
【问题描述】:
我已经实现了一个名为 contentByKey 的 Zend View Helper,它在我的 CMS 引擎中呈现一些 HTML。我想实现它,以便这个 View Helper 是我的标记中调用的唯一助手(传递了一个在 DB 中查找内容的键)。当它尝试构建 HTML 内容时,它需要能够在 View Helper 类中调度另一个 View Helpers 渲染。我的班级实现了 AbstractHelper。见下文:
class ContentByKey extends AbstractHelper{
public function __invoke($key){
/* 1. Fetch content from DB and check type */
/* 2. Content type = "foo";*/
/* 3. NEEDED LOGIC - Invoke fooHelper here (needs to process additional logic before rendering so simply rendering a different script isnt enough) */
}
如果这不是实现我需要的最佳方法,我很乐意接受任何其他建议。
【问题讨论】:
-
你想在
__invoke中调用另一个视图助手吗? -
是的,并且呈现视图助手内容而不是 ContentByKey 的
-
将你需要的ViewHelper注入到你自己的ViewHelper中
-
你能举个例子@Sam吗?
标签: php zend-framework zend-framework2 view-helpers