I've created my code as ZF2 pushes you to do it and now I'm starting to think that it's actually against the whole point/benefit of using namespacing in the first place.
I want to change everything but I'm scared to do it my way just because ZF didn't do it this way themselves so I feel like I have to be missing one important thing.
My folder/file structure is something like this:
- Application
- Controller
IndexController.php
- Model
- Table
User.php
Building.php
- Mapper
User.php
Building.php
- Entity
User.php
Building.php
So inside my controller, the code might look something like this, as ZF2 suggests you start out:
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController,
Zend\View\Model\ViewModel;
use Application\Model\Entity\User as UserEntity,
Application\Model\Mapper\User as UserMapper,
Application\Model\Table\User as UserTable;
class IndexController extends AbstractActionController {
public function indexAction() {
$userEntity = new UserEntity;
$userMapper = new UserMapper;
$userTable = new UserTable;
Right there I've only given a few items but as your application grows, you end up with a HUGE use statement and it seems like it should be done more like the following:
namespace Application;
use Zend\Mvc\Controller\AbstractActionController,
Zend\View\Model\ViewModel;
use Model;
class IndexController extends AbstractActionController {
public function indexAction() {
$userEntity = new Entity\User;
$userMapper = new Mapper\User;
$userTable = new Table\User;
I'm guessing it's because ZF2 are pushing Modular based projects that have lots of modules. But surely then I could just throw in that module's namespace if required? I would still need to do that with the more qualified names as currently in use.