Zend Framework,将变量传递给view

时间:2010-09-22 17:49:46

标签: php zend-framework

我在显示视图时遇到问题。当我将var传递给视图时,视图不会渲染。

控制器:

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不会出现。

此致

2 个答案:

答案 0 :(得分:13)

您只是在代码中缺少回显,htmlList视图助手返回一个值 - 它不会回显它。可以看到各种表单视图助手的一些示例here

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

答案 1 :(得分: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