Question

I love ZfcUser and use it most every project that I develop. It works great, but I am looking to expand my usage of it a bit.

Are there some examples that someone can offer about checking for identity in the controller? I have a function that fires when any action from a given function is accessed... I would like to add authentication to that function, but as I said, it runs in the controller.

Any advice (or documentation?) would be appreciated!

thanks

Was it helpful?

Solution

Checking for auth identity in any controller is pretty straightforward.

public function thatAction()
{
    $auth = $this->getServiceLocator()->get('zfcuser_auth_service');

    if( $auth->hasIdentity() )
        $user = $auth->getIdentity();
}

Pretty easy right! You can find more, here: https://github.com/ZF-Commons/ZfcUser/wiki/How-to-check-if-the-user-is-logged-in

The user object you get back, is your user entity. If you want to customize your user entity, I have small blog post here that may help: http://circlical.com/blog/2013/4/1/l5wftnf3p7oks5561bohmb9vkpasp6

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top