找不到Zend框架2 Zend \ config

时间:2014-03-12 13:21:41

标签: php zend-framework2

当我尝试使用以下命令创建xml文档时,我在Zf2上遇到了问题:

$config = new Zend\Config\Config(array(), true);

我按照官方文档: Zend framework 2 Zend\Config\writer

我确定zf2是装载机,我不明白那里发生了什么。

我的输出是

Fatal error: Class 'XmlGenerator\Controller\Zend\Config\Config' not found in C:\wamp\www\myLink\module\XmlGenerator\src\XmlGenerator\Controller\XmlGeneratorController.php

如果有人可以解释,我迷路了! :P

提前致谢!!

1 个答案:

答案 0 :(得分:2)

您遇到了命名空间问题。

您需要在声明名称空间或将代码更改为use Zend;之后将Zend命名空间包含$config = new \Zend\Config\Config(array(), true);

PHP正在寻找当前命名空间中的类,因此它正在添加当前命名空间以填充类的名称(在本例中为#34; XmlGenerator \ Controller"),自动装带器使用它来确定要获取的目录来自的班级。由于Zend代码与控制器不在同一目录中,因此自动加载器会阻塞并为您提供错误。

您需要告诉您的代码您还在使用Zend命名空间(通过use),或者您正在使用的类位于全局命名空间中(将\添加到类名称之前)