简体   繁体   English

找不到Zend框架2 Zend \\ config

[英]Zend framework 2 Zend\config not found

I have an issue on Zf2 when i try to create an xml document, using : 当我尝试使用以下命令创建xml文档时,我在Zf2上遇到问题:

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

i followed the official documentation here : Zend framework 2 Zend\\Config\\writer 我按照官方文档: Zend framework 2 Zend \\ Config \\ writer

I'm sure zf2 is loader and i don't understand what happening there but. 我确定zf2是加载器,我不明白那里发生了什么。

My output is 我的输出是

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

if someone can explain please, i'm lost ! 如果有人可以解释,我迷路了! :p :p

Thanks in advance !! 提前致谢 !!

You are having a namespacing problem. 您有一个命名空间问题。

You need to either include the Zend namespace with use Zend; 您需要use Zend;包含Zend名称空间use Zend; after where you declare the name space or change your code to $config = new \\Zend\\Config\\Config(array(), true); 在您声明名称空间或将代码更改为$config = new \\Zend\\Config\\Config(array(), true);

PHP is looking for class in your current namespace so it is adding the current namespace to fill name of the class (in this case "XmlGenerator\\Controller") which the autoloader uses to determine which directory to get the class from. PHP正在当前命名空间中查找类,因此它添加当前命名空间以填充类的名称(在本例中为“XmlGenerator \\ Controller”),自动装带器使用该名称来确定从哪个目录获取类。 Since the Zend code isn't in the same directory as your controller, the autoloader chokes and gives you the error. 由于Zend代码与控制器不在同一目录中,因此自动加载器会阻塞并为您提供错误。

You need to tell your code that you are also using the Zend namespace (via use ) or that the class you are using is in the global namespace (prepending the \\ to the class name) 您需要告诉您的代码您还在使用Zend命名空间(通过use ),或者您正在使用的类位于全局命名空间中(将\\前置于类名称之前)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM