ZF渲染一个动作并在另一个动作中获取html
我想要使用 Zend Framework 做的是从操作 X 渲染操作 Y 并获取 html:
示例:
public xAction(){
$html = some_function_that_render_action('y');
}
public yAction(){
$this->view->somedata = 'sometext';
}
其中 y 视图类似于:
<h1>Y View</h1>
<p>Somedata = <?php echo $this->somedata ?></p>
我找到了操作助手,但无法从控制器使用它。我该如何解决? 有可能吗?
What I want to do with Zend Framework is to render the action Y from the action X and to obtain the html:
Example:
public xAction(){
$html = some_function_that_render_action('y');
}
public yAction(){
$this->view->somedata = 'sometext';
}
where the y view is something like:
<h1>Y View</h1>
<p>Somedata = <?php echo $this->somedata ?></p>
I fount the action helper, but I cannot use it from a controller. How can I solve it?
It is possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是做你想做的事情的一种可能的方法。
而不是使用 ViewRenderer要设置要使用的视图脚本,您也可以像上面所示那样调用 yAction,但通过调用
$html = 获取 html $this->view->render('controller/y.phtml');
另请参阅 ActionStack 帮助器。
Here is one possible way to do what you want.
Instead of using the ViewRenderer to set the view script to use, you could also call yAction as I showed above, but get the html by calling
$html = $this->view->render('controller/y.phtml');
See also the ActionStack helper.
您可以从控制器使用 Action View Helper
它不是很漂亮,但效果很好,而且您不必使用
$view->setScriptPath($this->view->getScriptPaths());
这个助手为 yAction() 创建一个新的 Zend_Controller_Request,因此您可以将自己的参数作为第四个参数或使用
$this->getRequest()->getParams()
用于传播xAction()的请求参数。http://framework .zend.com/manual/1.12/en/zend.view.helpers.html#zend.view.helpers.initial.action
You can use the Action View Helper from the controller
It's not very beautiful but it works well and you don't have to use
$view->setScriptPath($this->view->getScriptPaths());
This helper creates a new Zend_Controller_Request for yAction(), so you can give your own parameters as 4th argument or use
$this->getRequest()->getParams()
to spread the request parameters of xAction().http://framework.zend.com/manual/1.12/en/zend.view.helpers.html#zend.view.helpers.initial.action
最后我找到了这个“解决方案”,这不是我想做的,但它有效,如果有人找到真正的解决方案,请在这里回答。
Finally I found this "solution", it's not what I want to do, but it works, if someone found the real solution, please answer here.