Zend Framework 中布局所需的代码放在哪里?
我使用 Zend_Layout 作为 Zend Framework 应用程序的布局。很简单,但是我在布局中还需要做一些操作。目前,代码包含在 PHP 括号之间,但我觉得这并不是最干净的方法。
我看到人们使用插件,但我认为这不是我想要的方式。显然,我可以提取“复杂”部分,以良好的操作/控制器方式进行操作,并在布局中使用占位符。这是要走的路吗?您是否有此类示例(例如在其自己的操作中委托的导航菜单)?
I am using Zend_Layout for the layout of my Zend Framework application. It is very simple, but I still have a few operations that I need to do in the layout. For now, the code is included between PHP brackets, but I feel like this is not really the cleanest way to go.
I saw people using plugins, but I don't think this is the way I want to go. Oviously, I could extract the "complicated" part, do it in a nice action/controller manner, and use a placeholder in the layout. Is this the way to go ? Do you have examples of such things (for instance the navigation menu delegated in its own action) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
navigation()
是占位符视图助手的具体实现。您可以创建相同的占位符实现,或使用
$this->render('script.phtml');
这取决于您需要什么。
正如您可能已经听说过的那样,动作堆栈是邪恶的。
navigation()
is a concrete implementation of placeholder view helper.You may create the same placeholder implementation, or use
$this->render('script.phtml');
It depends what do you need.
Action stack is evil, as you probably already heard.
正如 Takehin 所说,navigation() 占位符可能是正确的选择。但是,我不想针对这种特殊情况进行 Zend_Navigation 的设置,因此我使用了 自定义视图助手。
application/views/helpers/Menu.php
:application/views/scripts/helpers/menu.phtml
:这样,我可以简单地从我的布局中调用这个助手:
As takeshin said, the navigation() placeholder is probably the way to go. However, I did not want to go through the setup of Zend_Navigation for this particular case, so I used a custom view helper.
application/views/helpers/Menu.php
:application/views/scripts/helpers/menu.phtml
:This way, I can simply call this helper from my layout :