【问题标题】:Zend Framework, passing variables to viewZend Framework,将变量传递给视图
【发布时间】:2010-09-22 17:49:46
【问题描述】:

我在显示视图时遇到问题。当我将 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 不会出现。

问候

【问题讨论】:

  • 您的代码看起来不错。如果您在 index.phtml 中使用 var_dump($this->menu),那会起作用吗?

标签: php zend-framework


【解决方案1】:

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

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

【讨论】:

    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-05
      • 2012-04-25
      • 1970-01-01
      • 1970-01-01
      • 2016-03-26
      • 2011-10-01
      • 1970-01-01
      相关资源
      最近更新 更多