duanpo2813 2010-01-25 19:44
浏览 19
已采纳

zend_form ViewScript装饰器/传递参数

I have a form that is extend from Zend_Form. I am placing the form into a ViewScript decorator like this:

$this->setDecorators(array(array('ViewScript', array('viewScript' => 'game/forms/game-management.phtml'))));

I'd like to pass in a variable to this ViewScript but am not sure how this could be done.

Since the partial renders out as a Zend_View (allowing $this->app_store_icon for rendering), it seems like there should be a way to pass variables to be rendered. I tried the following but to no avail.

$this->setDecorators(array(array('ViewScript', array('viewScript' => 'game/forms/game-management.phtml'),array('app_store_picon'=>$current_app_store_picon))));

Any help on how to get this done would be appreciated.

thanks

  • 写回答

3条回答 默认 最新

  • douzhanhui5662 2010-01-25 20:56
    关注

    This one's a bit tricky, took me bout a half an hour to figure it out, but it can be done :)

    The point is, that you're passing the options to the ViewScript decorator and not to the element. Adding the option:

    $this->setDecorators(array(array('ViewScript', array(
        'viewScript' => 'test.phtml',
        'foo'=>'baz',
    ))));
    

    or an array of options:

    $this->setDecorators(array(array('ViewScript', array(
        'viewScript' => 'test.phtml',
        array(
            'foo'=>'baz',
            'spam'=>'ham',
        ),
    ))));
    

    Getting that out in the partial, test.phtml:

    $option = $this->element->getDecorator('ViewScript')->getOptions();
    

    In the first case, with one option passed it'll be $option['foo'] and in the second it'll be $option[0]['foo']

    HTH :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符