Closed Nirzol closed 7 years ago
@Nirzol I guess this is caused by the leading slash in your service name \ZfcRbac\View\Strategy\RedirectStrategy
:thinking:
$target = $event->getTarget();
//This strategy is used to redirect the user to another route when a user is unauthorized.
$target->getEventManager()->attach(
$target->getServiceManager()->get('\ZfcRbac\View\Strategy\RedirectStrategy')
);
better ? Or I miss understanding ?
$target = $event->getTarget();
//This strategy is used to redirect the user to another route when a user is unauthorized.
$target->getEventManager()->attach(
$target->getServiceManager()->get(RedirectStrategy::class)
);
But get : Catchable fatal error: Argument 2 passed to Zend\EventManager\EventManager::attach() must be callable, none given, called in .....Module.php on line 45 and defined in ...vendor/zendframework/zend-eventmanager/src/EventManager.php on line 185
Catchable fatal error: Argument 2 passed to Zend\EventManager\EventManager::attach() must be callable, none given, called in .....Module.php on line 45 and defined in ...vendor/zendframework/zend-eventmanager/src/EventManager.php on line 185
Yeah, now this error is because of the new way to attach listeners in EventManager v3, you should use
$listener->attach($eventManager);
instead of $eventManager->attach($listener);
.
btw I'm merging https://github.com/ZF-Commons/zfc-rbac/pull/361 which updates the docs about this :)
Ok Thanks ! But I think you miss something . $em not declared . Better like this ?
$app = $event->getApplication();
$sm = $app->getServiceManager();
$em = $app->getEventManager();
$listener = $sm->get(\ZfcRbac\View\Strategy\RedirectStrategy::class);
$listener->attach($em);
Good catch! Can you please send a PR to fix this?
Done
@Nirzol where? I don't see any PR :)
Sorry , I did it to fast.
Hello I try the new zf version ZF3 . I apologize is my issue is stupid... But I have an error when enable redirect strategy. Follow this link : https://github.com/ZF-Commons/zfc-rbac/blob/master/docs/05.%20Strategies.md#redirectstrategy
But get this error : Fatal error: Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotFoundException' with message 'Unable to resolve service "\ZfcRbac\View\Strategy\RedirectStrategy" to a factory; are you certain you provided it during configuration?' in /Users/egrondin/workspace/ZendSkeletonDescartes/vendor/zendframework/zend-servicemanager/src/ServiceManager.php on line 681
Can someone help me ? Thx