[英]How to render an action from another action in Symfony 1
I am stuck with a Symfony application using version 1.0.17 which can't be upgraded at the moment. 我陷入了使用1.0.17版本的Symfony应用程序的问题,该应用程序目前无法升级。
Right now there is a page that contains an iframe which loads a webpage of a different action from the same module. 现在,有一个页面包含一个iframe,该页面加载了与同一模块不同的操作的网页。 The iframe is causing some design issues as well and some user-experience issues so I want to get rid of it and just render the HTML from the iframe directly in the page.
iframe也会引起一些设计问题和一些用户体验问题,因此我想摆脱它,而直接在页面中呈现iframe的HTML。
I just can't figure out how to execute another action and render the view template into a variable that I can assign to the calling action's view. 我只是无法弄清楚如何执行另一个动作并将视图模板渲染为可以分配给调用动作的视图的变量。
I've tried getPresentationFor()
but that either results in a 404 on the calling page, an exception or fatal error depending on how I try it. 我已经尝试过
getPresentationFor()
但是它要么在调用页面上导致404错误,要么是异常错误,或者是致命错误,具体取决于我如何尝试。
I think I need to put the code in the execute
method of the action. 我想我需要将代码放入动作的
execute
方法中。 The controller is an sfAction
object. 控制器是
sfAction
对象。 If I call $this->getController()
I get an sfWebController
object. 如果我调用
$this->getController()
, sfWebController
得到一个sfWebController
对象。
Calling: 致电:
$this->getController()->getPresentationFor('module', 'ContactIframeAction');
Results in a blank page; 结果为空白页; any code after that call does not get executed but if I output something before it I can see it on the page.
调用之后的任何代码都不会执行,但是如果我在此之前输出某些内容,则可以在页面上看到它。 No errors in the server error log.
服务器错误日志中没有错误。
Calling: 致电:
$this->getController()->getPresentationFor('module', 'ContactIframe');
just causes our 404 page to show so I think the previous call is closer to what I want. 只是导致我们的404页面显示出来,所以我认为上一个电话更接近我想要的电话。
Is there a way to render the output of another action from another action's code? 有没有办法从另一个动作的代码中呈现另一个动作的输出?
Thanks. 谢谢。
It's probably 可能是
$this->theContent = $this->getController()->getPresentationFor('module', 'contactIframe'); // minus 'c'
Use : 采用 :
// modules/mymodule/actions/actions.class.php
class myPageActions extends sfActions {
public function executeIndex() {
// ...
$this->theContent = $this->getController()->getPresentationFor('module', 'contactIframe');
}
}
// modules/mymodule/templates/indexSuccess.php
<?php echo $theContent ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.