使用 XML 文件将 url 参数传递给 Zend_Navigation
我正在使用 Zend Framework 1.10.8。
我想在我的layout.phtml 中创建一个面包屑部分。我的菜单中有一些链接具有动态网址参数,例如 http://mydomain.com/editor/ edit/id/42
我试图弄清楚如何将 id=XXX 传递给 Zend_Navigation,而 XXX 来自数据库并且在每个请求中都不同。
到目前为止,我发现的一种解决方案是将属性(例如 params_id)添加到我的 xml 声明中:
在 configs/navigation.xml 中
<pages>
<editor>
<label>Editor</label>
<controller>editor</controller>
<action>edit</action>
<params_id>id</params_id>
<route>default</route>
</editor>
</pages>
以及在循环浏览页面的控制器中,并动态添加我的参数 id = 42 (而 42 将从中的请求对象中检索)最终版本)
$pages = $this->view->navigation()->getContainer()->findAllBy('params_id','id');
foreach ($pages as &$page) {
$page->setParams(array(
'id' => 42,
'something_else' => 667
));
}
由于添加动态 url 参数似乎是 Zend_Navigation 的基本要求,我非常确定我的解决方案太复杂、太昂贵,并且必须有一个“开箱即用”的更简单的解决方案。
I am using Zend Framework 1.10.8.
I want to create a breadcrumb section in my layout.phtml. There are some links in my menu that have dynamic url parameters like http://mydomain.com/editor/edit/id/42
I try to figure out how to pass id=XXX to Zend_Navigation, while XXX comes from the database and is different in every request.
One solution I found so far is adding a property e.g. params_id to my xml declaration:
in configs/navigation.xml
<pages>
<editor>
<label>Editor</label>
<controller>editor</controller>
<action>edit</action>
<params_id>id</params_id>
<route>default</route>
</editor>
</pages>
and in the controller looping through the pages and dynamically adding my parameter id = 42 (while 42 would be retrieved from the request object in the final version)
$pages = $this->view->navigation()->getContainer()->findAllBy('params_id','id');
foreach ($pages as &$page) {
$page->setParams(array(
'id' => 42,
'something_else' => 667
));
}
As adding dynamic url parameters seems such a basic requirement for Zend_Navigation I am quite sure that my solution is too complicate, too expensive and there must be a much simplier solution "out of the box".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这很简单。只需在 XML 中写入即可
,这里是根据数据库数据动态执行此操作的示例
首先定义导航加载插件。将文件命名为 Navigation.php 并将其放置在 application/plugins/ 目录中。这是此类插件的示例:
然后在 Bootstrap 中初始化此插件
It is very simple. Just write in your XML
Here is example to do it dynamically based on database data
First define Navigation loading plugin. Name the file Navigation.php and place it in application/plugins/ directory. Here's an example of such plugin:
Then in you Bootstrap init this plugin
更新:我最终扔掉了 xml 文件。我现在做什么:
从 Zend_Request 检索动态参数,
An update: I finally ended up throwing away the xml file. What I do now:
dynamic parameters are retrieved from Zend_Request