Coder Social home page Coder Social logo

RedirectStrategy + zf3 about zfc-rbac HOT 8 CLOSED

Nirzol avatar Nirzol commented on July 19, 2024
RedirectStrategy + zf3

from zfc-rbac.

Comments (8)

danizord avatar danizord commented on July 19, 2024 2

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 #361 which updates the docs about this :)

from zfc-rbac.

danizord avatar danizord commented on July 19, 2024

@Nirzol I guess this is caused by the leading slash in your service name \ZfcRbac\View\Strategy\RedirectStrategy 🤔

from zfc-rbac.

Nirzol avatar Nirzol commented on July 19, 2024

$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

from zfc-rbac.

Nirzol avatar Nirzol commented on July 19, 2024

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);

from zfc-rbac.

danizord avatar danizord commented on July 19, 2024

Good catch! Can you please send a PR to fix this?

from zfc-rbac.

Nirzol avatar Nirzol commented on July 19, 2024

Done

from zfc-rbac.

danizord avatar danizord commented on July 19, 2024

@Nirzol where? I don't see any PR :)

from zfc-rbac.

Nirzol avatar Nirzol commented on July 19, 2024

Sorry , I did it to fast.

from zfc-rbac.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.