ZF2 namespace and file system

Posted by user1918648 on Stack Overflow See other posts from Stack Overflow or by user1918648
Published on 2013-11-12T03:50:41Z Indexed on 2013/11/12 3:53 UTC
Read the original article Hit count: 137

I have standard Application module in ZF2. It's configured by default, I didn't change anything. I just added some stuff:

module/
  Application/
    src/
      Application/
        Entity/
          Product/
            **Product.php**        
        Controller/
          **IndexController.php**

Product.php

namespace Application\Entity;

class Product
{

}

IndexController.php

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Application\Entity\Product;

class IndexController extends AbstractActionController
{
    public function indexAction()
    {       
        $product = new Product();   
    }
}

and I get following error:

Fatal error: Class 'Application\Entity\Product' not found in \module\Application\src\Application\Controller\IndexController.php on line 20

I use the same namespace, but it doesn't see it. Why?

P.S: If I will change Product.php to be the following:

namespace Application\Entity\Product;

class Product
{

}

then in the IndexController.php the following code will be working:

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Application\Entity\Product\Product;

class IndexController extends AbstractActionController
{
    public function indexAction()
    {       
        $product = new Product();   
    }
}

© Stack Overflow or respective owner

Related posts about php

Related posts about namespaces