简体   繁体   中英

Zend framework 2 Zend\config not found

I have an issue on Zf2 when i try to create an xml document, using :

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

i followed the official documentation here : Zend framework 2 Zend\\Config\\writer

I'm sure zf2 is loader and i don't understand what happening there but.

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

Thanks in advance !!

You are having a namespacing problem.

You need to either include the Zend namespace with use Zend; after where you declare the name space or change your code to $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. Since the Zend code isn't in the same directory as your controller, the autoloader chokes and gives you the error.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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