问题描述
我有一个简单的问题...如何将Project/application/layouts/scripts/default.phtml中的default.phtml的内容呈现为变量,因此可以获取其html.
I have a simple question... How could I render the contents of the default.phtml which is in Project/application/layouts/scripts/default.phtml to a variable, so I can have its html.
在索引控制器中,有一个动作和一个名为test的phtml文件,它将起作用:
In the index controller, with an action and a phtml file named test, this would work:
$html = $this->view->render('index/test.phtml');
但是,这当然不是:
$htmlDefaultLayout = $this->view->render('default.phtml');
我猜是因为default.phtml不在任何控制器中.
Since default.phtml is not inside any controller, I guess.
有什么好方法吗?
推荐答案
您可以添加到Zend_View
查找视图的路径,以便随后呈现default.phtml文件.
You can add to the path that Zend_View
looks in for views so you could then render the default.phtml file.
示例:
// add the layout directory to the path
$this->view->addScriptPath(APPLICATION_PATH . '/layouts/scripts/');
$htmlDefaultLayout = $this->view->render('default.phtml');
在Zend_View中添加到scriptPath的最后一个路径是第一个要检查的(LIFO).
The last path added to the scriptPath in Zend_View are the first to be checked (LIFO).
请参见查看脚本路径.
这篇关于如何在控制器内部的变量中捕获default.phtml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!