Hi Robert,

if you want to use a factory class you can do it like this:

/module/User/config/module.config.php
---------------------------------------------------------------------
    'controllers' => array(
        'invokables' => array(
            'user-admin' => 'User\Controller\AdminController',
        ),
        'factories' => array(
            'user'       => 'User\Controller\UserControllerFactory',
        ),
    ),
---------------------------------------------------------------------

/module/User/src/Controller/UserControllerFactory.php
---------------------------------------------------------------------

namespace User\Controller;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class UserControllerFactory implements FactoryInterface
{
    public function createService(
        ServiceLocatorInterface $serviceLocator
    )
    {
        $service    = $serviceLocator->getServiceLocator()
                                     ->get('User\Service\User');
        $controller = new UserController();
        $controller->setUserService($service);
        return $controller;
    }
}

---------------------------------------------------------------------

My UserController could also use the constructor to accept dependencies.

Regards,

Ralf

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to