【问题标题】:how to include zend phtml file to other phtml file如何将 zend phtml 文件包含到其他 phtml 文件中
【发布时间】:2013-10-19 10:03:35
【问题描述】:

我正在使用 zend 框架 1。

我需要在另一个文件中包含 phtml 文件并将参数发送到第一个文件。

例如:

我有 indexController.php

我在控制器内部定义了$numberOfItem

我需要在 index.phtml 内渲染(包含) menu.phtml 并向其发送$numberOfItem 变量

谢谢

【问题讨论】:

    标签: php zend-framework


    【解决方案1】:

    你可以使用 zend partial 来做到这一点

    在你的 index.phtml 中做

    echo $this->partial('yourfolder/menu.phtml', array('numberOfItem' => $numberOfItem));
    

    在您的 menu.phtml 中,您可以使用

    读取打印变量
    $this->numberOfItem
    

    【讨论】:

    • 这种情况下如何将menu.phtml中定义的变量放入index.phtml中?
    【解决方案2】:

    它的Zend partial。

    在 IndexController 中,您将照常将 numberOfItem 值传递给相应的视图。

        $this->view->numberOfItem = $numberOfItem;
    

    然后,在 index.phtml 中:

        echo $this->partial('viewfolder/menu.phtml', array('numberOfItem' => $this->numberOfItem));
    

    在menu.phtml中:

         echo $this->numberOfItem;
    

    部分路径中的 viewfolder 将与“view/scripts”中的相对文件夹相同。例如,即使您的 index.phtml 和 menu.phtml 都在同一个文件夹“application/views/scripts/index”中,您也需要将路径传递给 partial 作为 index/menu.phtml

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-16
      • 1970-01-01
      • 2011-01-16
      • 1970-01-01
      • 2014-04-28
      • 2014-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多