使用 Zend 框架创建动态侧边栏的最佳实践 [英] Best practice creating dynamic sidebar with zend framework

查看:25
本文介绍了使用 Zend 框架创建动态侧边栏的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Zend 框架创建动态侧边栏或其他非内容布局位置的最佳实践是什么.此时我创建了控制器女巫,我称之为 WidgetsController.在这个控制器中,我为我的侧边栏定义了一些带有侧边栏"响应段的动作,在 IndexController 中我用 $this->view->action(); 调用它们;功能,但我认为这不是创建动态侧边栏的最佳做法.感谢您的回答.

解决方案

你的问题没有提供很多细节.通常,我会说通过视图的渲染/部分方法将侧边栏加载为视图模板.所以从视图内部:

//$data 是你要传递给侧边栏的动态数据回声 $this ->partial('/path/to/sidebar.phtml',array('menuitems' => $data));

然后侧边栏可以处理该动态数据:

//sidebar.phtml<div id="侧边栏"><?php foreach($this -> menuitems as $item) : ?><a href="<?php echo $item['url']; ?>"><?php echo $item['title'];?></a><?php endforeach;?>

如果您需要额外的功能,您可以创建一个专用的视图助手 来处理它.

What is best practice to create dynamic sidebar or other non content layout places with zend framework. At this moment I created controller witch i called WidgetsController. In this controller i defined some actions with 'sidebar' response segment for my sidebar and in IndexController i call them with $this->view->action(); function but I don't think that is a best practice to create dynamic sidebar. Thanks for your answers.

解决方案

You question doesn't provide many details. Generally, I'd say load the sidebar as view template, via the render/partial methods of the view. So from inside a view:

//$data is dynamic data you want to pass to the sidebar
echo $this -> partial('/path/to/sidebar.phtml',array('menuitems' => $data));

And then sidebar could process that dynamic data:

//sidebar.phtml
<div id="sidebar">

    <?php foreach($this -> menuitems as $item) : ?>
    <a href="<?php echo $item['url']; ?>"><?php echo $item['title']; ?></a>
    <?php endforeach; ?>

</div>

If you need extra functionality, you could create a dedicated view helper to handle it.

这篇关于使用 Zend 框架创建动态侧边栏的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆