New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot attach event to RbacListener #237

Closed
webdevilopers opened this Issue Jun 2, 2014 · 2 comments

Comments

Projects
None yet
2 participants
@webdevilopers
Contributor

webdevilopers commented Jun 2, 2014

I tried to bind ZfcRbac to Zend\Navigation and followed this solution:
http://stackoverflow.com/questions/18941763/zend-navigation-and-rbac/18942160#18942160

public function onBootstrap(MvcEvent $e)
{
    $eventManager        = $e->getApplication()->getEventManager();
    $eventManager->getSharedManager()->attach(
        'Zend\View\Helper\Navigation\AbstractHelper', 
        'isAllowed', 
        array('\Application\Listener\RbacListener', 'accept')
    );
    $moduleRouteListener = new ModuleRouteListener();
    $moduleRouteListener->attach($eventManager);
}

But I get the following error:
Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method Application\Listener\RbacListener::accept() should not be called statically in /home/.../zendframework/library/Zend/EventManager/EventManager.php on line 468

Has something changed with the last versions?

Is there a best practice for binding to ZfcRbac?

@danizord

This comment has been minimized.

Show comment
Hide comment
@danizord

danizord Jun 2, 2014

Member

This is not a ZfcRbac issue, please use StackOverflow or ping us on IRC for questions.

Having said that, the problem is that you're trying to attach the static call array('RbacListener', 'accept') and RbacListener::accept() is not a static method. So, you should provide a non-static callback, like that: array($listenerInstance, 'method').

I made a gist for you to be more clear: https://gist.github.com/danizord/be431edeb9fa2581c63b

Member

danizord commented Jun 2, 2014

This is not a ZfcRbac issue, please use StackOverflow or ping us on IRC for questions.

Having said that, the problem is that you're trying to attach the static call array('RbacListener', 'accept') and RbacListener::accept() is not a static method. So, you should provide a non-static callback, like that: array($listenerInstance, 'method').

I made a gist for you to be more clear: https://gist.github.com/danizord/be431edeb9fa2581c63b

@webdevilopers

This comment has been minimized.

Show comment
Hide comment
@webdevilopers

webdevilopers Jun 2, 2014

Contributor

Thank you very much for that code, @danizord !
Works like a charm. I created a short tutorial for anybody interested: http://blog.webdevilopers.net/?p=9

Contributor

webdevilopers commented Jun 2, 2014

Thank you very much for that code, @danizord !
Works like a charm. I created a short tutorial for anybody interested: http://blog.webdevilopers.net/?p=9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment