简体   繁体   English

如何在Symfony 1中从另一个动作中呈现一个动作

[英]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.

相关问题 如何在Symfony 3中将表单变量从控制器操作传递到另一个变量 - How to pass a form variable from a controller action to another in Symfony 3 我如何执行(或要求执行)来自symfony 1.4上另一个动作文件的动作? - how can I execute (or ask to be executed) an action from another action file on symfony 1.4? 如何从另一个动作的角度调用动作? - how to call action from a view of another action? 如何禁用Symfony中的验证操作? - How to disable validation from action in symfony? Yii,是否可以从其他控制器/动作呈现其他信息? - Yii, Is possible to render another information from another controller/action? 如何从动作类渲染视图 - How to render a view from an action class 在symfony中的同一控制器中将发布的值从一个动作传递到另一个 - Passing posted values from one action to another in the same controller in symfony Symfony2-将POST从一个控制器动作中的纯HTML格式传递到另一个控制器动作 - Symfony2 - Passing POST from plain HTML form in one controllers action to another controllers action 如何从另一个控制器动作中访问控制器动作? - How to access a controller action from within another controllers action? Yii:如何从另一个控制器动作内部调用一个控制器动作? - Yii: how to invoke a controler action from inside another controller action?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM