After login, I want current user object in my class without creating service. Becauase I had already create current user pluggin and helper.
So If i need current user object in my class then How to get current user object.
i.e,
class CoreFunction
{
public static curentUserData()
{
// i want user object here
}
}
In Zend Framework 2, I just used:
class CoreFunction
{
public static curentUserData() {
$authService = $this->getServiceLocator()
->get('Zend\Authentication\AuthenticationService')
->getIdentity();
}
}
How can I do this in Zend Framework 3?
As in ZF2, you should have access to controller plugin identity and use it like $this->identity()
// From the doc.
public function testAction()
{
if ($user = $this->identity()) {
// someone is logged !
} else {
// not logged in
}
}
If you want to use it in other class than controller, than you need to inject it, as in ZF2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With