1

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

4

1 回答 1

3

在任何控制器中检查身份验证身份非常简单。

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

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

很容易吧!您可以在此处找到更多信息: https ://github.com/ZF-Commons/ZfcUser/wiki/How-to-check-if-the-user-is-logged-in

您返回的用户对象是您的用户实体。如果您想自定义您的用户实体,我在这里有一些小博客文章可能会有所帮助:http ://circlical.com/blog/2013/4/1/l5wftnf3p7oks5561bohmb9vkpasp6

于 2013-04-20T02:26:41.967 回答