dongsi073898 2014-07-09 16:10
浏览 30
已采纳

如何将值发送到视图?

I'm trying to send some values to the view (layout + partials) using this code (all of these variables have 1 as value).

$this->layout()->setVariables(array(
    'nbTotalLignes'     => $nbTotalLignes,
    'nbTotalPages'      => $nbTotalPages,
    'comptes'           => $comptes,
    'numPageCourante'   => $numPageCourante,
    'nbComptesAffiches' => $nbComptesAffiches,
    'comptesAffiches'   => $comptesAffiches,
));

But when I try to display these in the view using this code echo (isset($this->nbTotalLignes)?1:0, I get 0. How do I please to fix that ?

  • 写回答

1条回答 默认 最新

  • doulu4316 2014-07-10 05:22
    关注

    each view has its own scope. $this->layout()->setVariables set the variables for the layout and not your current actions view.

    to send vars to the current actions view you have 2 options :

    return array('var1'=>1);
    

    zend will automatically convert this to a viewmodel. or

    $view = new ViewModel();
    $view->setVariables(array('var1'=>1))
    return $view;
    

    with this approach you can also set a different template

    $view->setTemplate('a different template path'); 
    

    and choose not to render layout

    $view->setTerminal(true)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器