2010-09-22 98 views
2

我在顯示視圖時遇到了問題。當我傳遞var來查看時,視圖不會呈現。Zend Framework,傳遞變量以查看

控制器:

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

視圖(index.phtml):

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

當我嘗試調試$branches不分配它來查看,一切似乎是確定,但是當我試圖將其推查看,index.phtml不會出現。

問候

+1

你的代碼看起來不錯。如果你在你的index.phtml中var_dump($ this-> menu),這是否工作? – 2010-09-22 18:29:07

回答

12

你只是缺少一個回波在你的代碼中,htmlList視圖助手返回一個值 - 它沒有迴音了。各種形式的視圖助手的一些例子可以看出here

​​
2

控制器

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

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

視圖

echo $this->variableName;//echo here 

    echo $this->variableName1;//echo here