duanjian7617 2013-10-14 09:32
浏览 46
已采纳

呈现不同的视图脚本,将数据传递到该视图并在Zend中获取输出

I want to render a different view in my action, pass data from action to that view and get its output in a variable.

I know that

  $output = $this->view->render('path/to/script');

render different view script and returns output. But I also want to pass data to this script from my action but not succeeded so far. I have used

 $this->view->data = $data

But it doesn't send data to this script.

Can any one guide how can I do it?

  • 写回答

1条回答 默认 最新

  • douquanqiao6788 2013-10-14 09:50
    关注

    You can pass an array of data to the view script:

    $this->view->render('path/to/script/script', array('someValue' => true)); 
    

    Access it in the view script with:

    <?= $this->someValue ?>
    

    EDIT: In a controller I always use...

    $this->view->assign('someValue', 'data');
    

    EDIT: With layout pattern... You need to set a variable in the controller for the path of the view script you want to use in the layout template and any variables/data you want passing to the view partial.

    In controller:

    $this->view->assign('partialPath', 'path/to/partial');
    $this->view->assign('partialdata', 'value');
    

    In Layout:

    $this->view->render($this->partialPath, $this->partialData) //renders partial and passes data
    

    In partial:

    <?= $this->partialData ?> // echos data
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误