2
votes

I have read Extending ZfcUser's UserController in custom module and and did everything as it was written but I still getting error:

/vagrant/app/vendor/zf-commons/zfc-user/src/ZfcUser/Controller/UserController.php:69 You must supply a callable redirectCallback

Stack trace:
#0 /vagrant/app/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php(207): ZfcUser\Controller\UserController->__construct()
#1 /vagrant/app/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(642): Zend\ServiceManager\AbstractPluginManager->createFromInvokable('zfcuser', 'zfcuser')
#2 /vagrant/app/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(598): Zend\ServiceManager\ServiceManager->doCreate('zfcuser', 'zfcuser')
#3 /vagrant/app/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(530): Zend\ServiceManager\ServiceManager->create(Array)
#4 /vagrant/app/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php(116): Zend\ServiceManager\ServiceManager->get('zfcuser', false)
#5 /vagrant/app/vendor/zendframework/zend-mvc/src/Controller/ControllerManager.php(137): Zend\ServiceManager\AbstractPluginManager->get('zfcuser', Array, false)
#6 /vagrant/app/vendor/zendframework/zend-mvc/src/Controller/Plugin/Forward.php(121): Zend\Mvc\Controller\ControllerManager->get('zfcuser')
#7 /vagrant/app/vendor/socalnick/scn-social-auth/src/ScnSocialAuth/Controller/UserController.php(118): Zend\Mvc\Controller\Plugin\Forward->dispatch('zfcuser', Array)
#8 /vagrant/app/vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php(82): ScnSocialAuth\Controller\UserController->loginAction()
#9 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#10 /vagrant/app/vendor/zendframework/zend-eventmanager/src/EventManager.php(444): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#11 /vagrant/app/vendor/zendframework/zend-eventmanager/src/EventManager.php(205): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#12 /vagrant/app/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php(118): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#13 /vagrant/app/vendor/zendframework/zend-mvc/src/DispatchListener.php(93): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#14 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#15 /vagrant/app/vendor/zendframework/zend-eventmanager/src/EventManager.php(444): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#16 /vagrant/app/vendor/zendframework/zend-eventmanager/src/EventManager.php(205): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#17 /vagrant/app/vendor/zendframework/zend-mvc/src/Application.php(314): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#18 /vagrant/app/public/index.php(21): Zend\Mvc\Application->run()
#19 {main}

In MyModule\Module.php I did like this:

public function getControllerConfig()
{
    return array(
        'factories' => array(
            'User\Controller\User' => function($controllerManager) {
                $serviceManager = $controllerManager->getServiceLocator();
                $redirectCallback = $serviceManager->get('zfcuser_redirect_callback');
                $controller = new \ZfcUser\Controller\UserController($redirectCallback);
                return $controller;
            },
        ),
    );
}

My extended User Controller looks like:

class UserController extends \ZfcUser\Controller\UserController {
    public function loginAction() {
        // customs actions 
}

I also included ScnSocialAuth module that have own UserController. Why I want to do it that way? I'm writing SPA application (Backbone+Marionette) and I need modal authentication. Maybe I missed something, or something wrong call - please help fix. I tried different ways but this would be the most optimal. In addition, the answer will be useful to other users. Thanks.

2

2 Answers

2
votes

Controllers have their own config:

public function getControllerConfig()
{
  return [
    'factories' => [
    // snip

Your error message says createFromInvokable in the trace. Make sure you don't have an invokable with the same locator name.

Also, your factory is returning the ZfcUser controller, not your custom one.

0
votes

In order to extend ZfcUser controller in Module.php must be:

public function getControllerConfig()
{
    return array(
        'factories' => array(
            'User\Controller\User' => function($controllerManager) {
                $serviceManager = $controllerManager->getServiceLocator();
                $redirectCallback = $serviceManager->get('zfcuser_redirect_callback');
                $controller = new \User\Controller\UserController($redirectCallback);
                return $controller;
            },
        ),
    );
}

and need to call custom user class instead zfcuser. Also my mistake was that in my module.config.php was it:

'controllers' => array(
    'invokables' => array(
        'User\Controller\User' => 'User\Controller\UserController'
    ),
),

Because of this, my factory is not called.