Zend Navigation(面包屑)不显示
我在使用 Zend_Navigation 显示面包屑时遇到问题。
我有一个控制器,它接受一个参数来从数据库中查询文章。因此,如果您指向“articles/view/id/3”,它会返回 id 为 3 的文章。我遇到的问题是让面包屑在这种逻辑下工作。理想情况下,当转到“articles/view/id/3”时,我希望面包屑为:“Articles > Article_Name”
我的代码可以正常渲染导航和子导航,它只是在面包屑上失败,当前不显示任何内容。
这是我的代码:
1) XML 格式的站点导航,如下所示:
<?xml version="1.0"?>
<zend-config xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/">
<nav>
<articles>
<label>Articles</label>
<uri>/</uri>
<order>1</order>
<active>1</active>
<visible>1</visible>
<pages>
<article_one>
<label>Article One</label>
<uri>/articles/view/id/81e728d9d4c2f636f067f89cc14862c</uri>
<order>1</order>
<active>1</active>
<visible>1</visible>
</article_one>
</pages>
</articles>
</nav>
</zend-config>
2) 导航(在布局中):
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
$nav = new Zend_Navigation($config);
$view = new Zend_View();
$view->navigation($nav);
echo $view->navigation()->menu();
3) 面包屑(在文章控制器中):
public function init() {
$uri = $this->_request->getPathInfo();
$activeNav = $this->view->navigation()->findByUri($uri);
$activeNav->class = "selected";
$activeNav->active = true;
}
4) 面包屑(在布局中):
//Doesn't display anything[/B]
echo $view->navigation()->breadcrumbs()->setLinkLast(true);
提前感谢您的帮助!
I'm having a problem displaying breadcrumbs with Zend_Navigation.
I have a single controller that takes in a parameter to query out articles from the DB. So, if you point to "articles/view/id/3", it returns the article with an id of 3. The problem I'm having is having breadcrumbs work under this logic. Ideally, when going to "articles/view/id/3" I'd like the breadcrumbs to be: "Articles > Article_Name"
My code renders the navigation and sub navigation alright, it just fails on the breadcrumbs, currently not displaying anything.
Here's my code:
1) Site's navigation in an XML format that looks like:
<?xml version="1.0"?>
<zend-config xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/">
<nav>
<articles>
<label>Articles</label>
<uri>/</uri>
<order>1</order>
<active>1</active>
<visible>1</visible>
<pages>
<article_one>
<label>Article One</label>
<uri>/articles/view/id/81e728d9d4c2f636f067f89cc14862c</uri>
<order>1</order>
<active>1</active>
<visible>1</visible>
</article_one>
</pages>
</articles>
</nav>
</zend-config>
2) Navigation (In the layout):
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
$nav = new Zend_Navigation($config);
$view = new Zend_View();
$view->navigation($nav);
echo $view->navigation()->menu();
3) Breadcrumbs (in the Articles controller):
public function init() {
$uri = $this->_request->getPathInfo();
$activeNav = $this->view->navigation()->findByUri($uri);
$activeNav->class = "selected";
$activeNav->active = true;
}
4) Breadcrumbs (In the layout):
//Doesn't display anything[/B]
echo $view->navigation()->breadcrumbs()->setLinkLast(true);
Thanks in advance for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
URI 的参数是什么?
参数
controller
& 在哪里?行动
?您可以在这里查看 http://framework.zend.com/manual/ru /zend.view.helpers.html
或者源码
Zend/View/Helper/Navigation/Breadcrumbs.php
For what parameters URI for?
Where are parameters
controller
&action
?Your can look here http://framework.zend.com/manual/ru/zend.view.helpers.html
Or source code
Zend/View/Helper/Navigation/Breadcrumbs.php
只是指出这一点,Actualli 面包屑与 uri 一起使用。
问题是
$this->view->navigation()->findByUri($uri)
返回一个 null 对象;因为即使它是在引导程序中设置的,它也不会被看到。
在引导文件中添加
Zend_Registry::set('Zend_Navigation', $navigation);
应该可以解决问题。干杯
Just to point this out, Actualli breadcrumbs work with uri.
The problem is that
$this->view->navigation()->findByUri($uri)
returns a null object;because even though it is setup in the bootstrap its not seen.
Adding
Zend_Registry::set('Zend_Navigation', $navigation);
in your bootstrap file should solve the problem.Cheers
尝试将
/
添加到 URL。我也有同样的问题。Try adding
/
to the URL. I had the same problem too.