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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan