Zend Framework, passing variables to view

╄→гoц情女王★ 提交于 2020-01-21 09:04:50

问题


I have a problem with displaying a view. When I pass var to view, view doesn't render.

Controller:

public function indexAction()
{
    $branchModel = new Application_Model_Branches();
    $branches = $branchModel->getAllBranches();
    $this->view->menu = $branches;
}

View (index.phtml):

<h2>Menu</h2>
<?php
    $this->htmlList($this->menu);
?>

When I try debug $branches without assign it to view, all seems to be ok, but when I try push it to view,index.phtml don't appear.

Regards


回答1:


You're just missing an echo in your code, the htmlList view helper returns a value - it doesn't echo it. Some examples of the various form view helpers can be seen here

<h2>Menu</h2>
<?php
    echo $this->htmlList($this->menu);
?>



回答2:


controller

    $this->view->variableName = "Hello World!";//assign here        

    $this->view->assign('variableName1', "Hello new World!");//assign here

view

    echo $this->variableName;//echo here

    echo $this->variableName1;//echo here


来源:https://stackoverflow.com/questions/3772138/zend-framework-passing-variables-to-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!