Php zend_Config_Xml的zend导航问题
我正在尝试实现Zend_导航——创建菜单和面包屑 在引导文件中Php zend_Config_Xml的zend导航问题,php,zend-framework,zend-navigation,Php,Zend Framework,Zend Navigation,我正在尝试实现Zend_导航——创建菜单和面包屑 在引导文件中 ... class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { protected $_config; protected $_layout; protected function _initConfig() { $this->_config = new Zend_Config_Ini(APPLICATION_PA
...
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
protected $_config;
protected $_layout;
protected function _initConfig() {
$this->_config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini');
Zend_Registry::set("config", $this->_config);
if ($this->_config->debug) {
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'on');
}
$request = new Zend_Controller_Request_Http();
$uri = $request->getRequestUri();
if (preg_match("/admin/", $uri)) {
//echo $this->_config->layout->admin->layout; exit;
$this->_layout = Zend_Layout::startMvc(
array(
'layoutPath' => $this->_config->layout->layoutPath,
'layout' => $this->_config->layout->admin->layout
)
);
} else {
$this->_layout = Zend_Layout::startMvc(
array(
'layoutPath' => $this->_config->layout->layoutPath,
'layout' => $this->_config->layout->layout)
);
//echo $this->_view = $this->_layout->getView(); exit;
}
}
/**
* used for handling top-level navigation
* @return Zend_Navigation
*/
protected function _initNavigation()
{
$view = $this->_layout->getView();
/*
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
*/
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml','nav');
$container = new Zend_Navigation($config);
$view->navigation($container);
}
...
下面是application/config文件夹下的navigation.xml
<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<nav>
<home>
<label>Home</label>
<uri>/</uri>
<pages>
<index>
<label>Home</label>
<uri>/index/index</uri>
</index>
<index>
<label>Product</label>
<uri>/index/product</uri>
</index>
</pages>
</home>
</nav>
</configdata>
家
/
家
/索引/索引
产品
/索引/产品
在布局文件中
...
<div class="breadcrumbs">
<?= $this->navigation()->breadcrumbs()->setMinDepth(0)->setLinkLast(true)->setSeparator(" : "); ?>
</div>
...
。。。
...
当我运行该站点时,我得到了以下错误:
致命错误:未捕获的异常“Zend\u导航\u异常”与
消息“无效参数:无法确定要实例化的类”
在C:\xampp\htdocs\enit\library\Zend\Navigation\Page.php:235堆栈中
跟踪:#0
C:\xampp\htdocs\enit\library\Zend\Navigation\Container.php(117):
Zend_导航页面::工厂(阵列)#1
C:\xampp\htdocs\enit\library\Zend\Navigation\Container.php(164):
Zend_导航_容器->添加页面(数组)#2
C:\xampp\htdocs\enit\library\Zend\Navigation\Container.php(179):
Zend_导航_容器->添加页面(数组)#3
C:\xampp\htdocs\enit\library\Zend\Navigation\Page.php(852):
Zend_导航_容器->设置页面(数组)#4
C:\xampp\htdocs\enit\library\Zend\Navigation\Page.php(295):
Zend_导航页面->设置('页面',数组)#5
C:\xampp\htdocs\enit\library\Zend\Navigation\Page.php(250):
Zend_导航页面->设置选项(数组)#6
C:\xampp\htdocs\enit\library\Zend\Navigation\Page.php(232):
Zend_导航页面->_构造(数组)#7
C:\xampp\htdocs\enit\library\Zend\Navigation\Container.php(117):
Zend_Navigation_P in
第235行的C:\xampp\htdocs\enit\library\Zend\Navigation\Page.php
我在stackoverflow和google上搜索了一些解决方案,但没有找到。我在这方面做错了什么?请注意我已经运行了您的代码。错误在配置中。您有两个同名的兄弟姐妹,Zend_Config_Xml将其添加到此表单
array
'label' => string 'Home' (length=4)
'uri' => string '/' (length=1)
'pages' =>
array
'index' =>
array
0 =>
array
'label' => string 'Home' (length=4)
'uri' => string '/index/index' (length=12)
1 =>
array
'label' => string 'Product' (length=7)
'uri' => string '/index/product' (length=14)
当您查看Zend_Mvc_页面第235行时,您可以了解引发异常的原因
$hasUri = isset($options['uri']);
$hasMvc = isset($options['action']) || isset($options['controller']) ||
isset($options['module']) || isset($options['route']);
if ($hasMvc) {
require_once 'Zend/Navigation/Page/Mvc.php';
return new Zend_Navigation_Page_Mvc($options);
} elseif ($hasUri) {
require_once 'Zend/Navigation/Page/Uri.php';
return new Zend_Navigation_Page_Uri($options);
} else {
require_once 'Zend/Navigation/Exception.php';
throw new Zend_Navigation_Exception(
'Invalid argument: Unable to determine class to instantiate');
}
最后,解决方案是更改第二个同级名称。在“有两个节点”下,尝试重命名them@Ashley谢谢,现在错误已经修复