Zend Framework, passing variables to view

2020-03-28 18:12发布

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

2条回答
迷人小祖宗
2楼-- · 2020-03-28 18:37

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
查看更多
一纸荒年 Trace。
3楼-- · 2020-03-28 18:51

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);
?>
查看更多
登录 后发表回答