Marek
Marek

Reputation: 21

Zend Framework, passing variables to view

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

Upvotes: 2

Views: 9347

Answers (2)

000
000

Reputation: 3950

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

Upvotes: 0

robjmills
robjmills

Reputation: 18598

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

Upvotes: 14

Related Questions