开发者

Zend Framework, passing variables to view

开发者 https://www.devze.com 2023-01-17 17:15 出处:网络
I have a problem with displaying a view. When I pass var to view,开发者_如何学JAVA view doesn\'t render.

I have a problem with displaying a view. When I pass var to view,开发者_如何学JAVA 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


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);
?>


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
0

精彩评论

暂无评论...
验证码 换一张
取 消