ZF2 namespace and file system
- by user1918648
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();
}
}