I'm new to Zend Framework 3. And migrating my Zend Framework 2 application to Zend Framework 3.
Currently I'm trying to call userPlugin
from Application Module's Module.php
file.
Here is my code,
public function onRoute(MvcEvent $e)
{
$sm = $e->getApplication()->getServiceManager();
$userPlugin = $sm->get('ControllerPluginManager')->get('userPlugin');
$userPlugin->setServiceManager($e->getApplication()->getServiceManager());
$checkLogin = $userPlugin->isLoggedIn();
}
And in my module.config.php
,
'controller_plugins' => array(
//This is also not working
//'invokables' => array(
// 'userPlugin' => 'User\Controller\Plugin\UserPlugin',
//),
'factories' => [
Controller\Plugin\UserPlugin::class => InvokableFactory::class,
],
'aliases' => [
'userPlugin' => Controller\Plugin\UserPlugin::class,
]
)
But getting this error
Uncaught Zend\ServiceManager\Exception\ServiceNotFoundException: A plugin by the name "UserPlugin" was not found in the plugin manager Zend\Mvc\Controller\PluginManager
Where am I wrong?
->get(\MyModule\Controller\Plugin\UserPlugin::class)
instead of->get('UserPlugin')
. Could you check if that is working? – KwidoModule.php
class or how do you attach toroute
event? Also, does your plugin work in controller? – SzymonM->get('userPlugin')
do not match up. "UserPlugin" (in error message) is not "userPlugin" (as shown in your example). @Kwido is correct, In ZF3 this will cause you an issue as the service names are literal strings. Are you sure you are using->get('userPugin')
and not->get('UserPlugin');
. – AlexP