这是一个自定义CMS,其中菜单列表可以在后端编辑,然后需要在前端布局中显示。
菜单控制器位于 - / application / modules / admin / controllers
并且渲染操作的代码是:
<?php
class Admin_MenuController extends CMS_Controller_AdminbaseController
{
public function renderAction()
{
$menu = $this->_request->getParam('menu');
$mdlMenuItems = new Model_MenuItems();
$menuItems = $mdlMenuItems->getItemsByMenu($menu);
if(count($menuItems)>0){
foreach($menuItems as $item){
$label = $item->label;
if(!empty($item->link)){
$uri = $item->link;
}else{
$uri = '/page/open/id/' . $item->pageId;
}
$itemArray[] = array(
'label' => $label,
'uri' => $uri
);
}
$container = new Zend_Navigation($itemArray);
$this->view->navigation()->setContainer($container);
}
}
}
使用
在 - /application/modules/admin/views/scripts/menu/render.phtml 中呈现时<? echo $this->navigation()->menu(); ?>
它渲染得很好,但我想在 / application / layouts / scripts 中渲染它。 任何帮助深表感谢。
答案 0 :(得分:0)
以Zend_View_Helper创建exapmle.php为例;
就插入功能
public function abc()
{
//insert your code here
}
然后转到layout.phtml并调用它
echo $this->abc();
答案 1 :(得分:0)
您可以通过这种方式在布局中呈现<?= $this->action('render', 'menu', 'admin');?>
另外,您可以在数组中传递一些参数。
希望这会对你有所帮助。