【问题标题】:Pass a variable from an action to another action's view in ZF将变量从一个动作传递到 ZF 中另一个动作的视图
【发布时间】:2013-09-20 13:11:06
【问题描述】:

我想知道zend是否允许这个东西,如果是的话比怎么做?

public xAction()
{
// code here
}

public yAction(){
 $this->_helper->viewRenderer('x');
// code here....
// $this->view->variable= $somedata;
}

**x.phtml**

<?php echo $this->variable; ?>

【问题讨论】:

    标签: php zend-framework variable-assignment


    【解决方案1】:

    Zend 允许渲染不同的视图脚本。 你可以这样做:$this-&gt;_helper-&gt;viewRenderer('controller/action', null, true);
    More info here(示例 #11)

    【讨论】:

    • 我必须在哪个动作中写这个?
    • 在你的情况下是 y 动作。类似$this-&gt;_helper-&gt;viewRenderer('x');
    • 我已经这样做了我想在 x.phtml 中访问$this-&gt;view-&gt;variable= $somedata;
    • 如果您在当前(在您的情况下为y)操作中设置它应该可以访问。
    • 您应该在*Action(x,y or other) 函数中设置var,该函数使用.phtml 文件作为视图脚本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-27
    • 1970-01-01
    相关资源
    最近更新 更多