Zend 重用视图
对于我创建的每个新控制器和操作,Zend 期望在 /views/scripts/controllername
中有一个模板文件。但是,我希望多个操作共享一个模板,可以将数据库中的文本注入到该模板中。
我目前使用布局并通过 echo $this->layout()->content 委托页面特定视图
。我尝试了以下操作:
class SomeController extends Zend_Controller_Action{
public function someAction() {
$path = $this->view->getScriptPath();
$this->view = new Zend_View();
$this->view->setScriptPath($path);
$this->view->render('default.phtml');
}
}
但是,我收到一个错误,指出在路径中找不到脚本“some/some.phtml”。我该如何正确地做到这一点?
For every new controller and action I create, Zend expects a template file in /views/scripts/controllername
. However, I would like to have multiple actions share a single template into which text from a database can be injected.
I currently use a layout and delegate page specific views with echo $this->layout()->content
. I tried the following:
class SomeController extends Zend_Controller_Action{
public function someAction() {
$path = $this->view->getScriptPath();
$this->view = new Zend_View();
$this->view->setScriptPath($path);
$this->view->render('default.phtml');
}
}
However, I get an error that the script 'some/some.phtml' not found in path. How do I do this correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须使用“默认”(不带扩展名)并直接调用该方法(不在视图上),例如
请参见 Zend_Controller_Action::render
如果您想提供特定的脚本,请使用
参见 Zend_Controller_Action::renderScript
You have to use 'default' (without the extension) and call the method directly (not on the view), e.g.
See Zend_Controller_Action::render
If you want to provide a specific script, use
See Zend_Controller_Action::renderScript
如果您选择使用 viewRenderer 并且需要从另一个控制器中选择视图,则必须将 $noController 参数设置为 TRUE:
BookController:
这将查找视图 < em>/views/scripts/approval/index.phtml 而不是默认的 /views/scripts/book/save-book.phtml。
If you would choose to use viewRenderer and you would need to pick a view from another controller you must set $noController parameter to TRUE:
BookController:
This would look for the view /views/scripts/approval/index.phtml instead of the default /views/scripts/book/save-book.phtml.