加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

zend-framework – ZF渲染动作并在另一个动作中获取html

发布时间:2020-12-13 16:23:32 所属栏目:PHP教程 来源:网络整理
导读:我想用Zend Framework做的是从动作X渲染动作Y并获取html: 例: public xAction(){ $html = some_function_that_render_action('y');}public yAction(){ $this-view-somedata = 'sometext';} y视图的位置如下: h1Y View/h1pSomedata = ?php echo $this-some
我想用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>

我配置动作帮助器,但我无法从控制器中使用它.我该如何解决?
有可能的?

解决方法

这是一种可能的方式来做你想要的.

public function xAction()
{
    $this->_helper
         ->viewRenderer
         ->setRender('y'); // render y.phtml viewscript instead of x.phtml

    $this->yAction();

    // now yAction has been called and zend view will render y.phtml instead of x.phtml
}

public function yAction()
{
    // action code here that assigns to the view.
}

我没有使用ViewRenderer设置要使用的视图脚本,也可以像上面所示调用yAction,但是通过调用$html = $this-> view-> render(‘controller / y.phtml’)来获取html. );

另见ActionStack helper.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读