Search code examples
zend-framework2hybridauth

Can I use $this->hybridauthinfo() in Controller of ZF2?


I confirmed $this->hybridauthinfo() works fine into View of ZF2.

But I'd like to use it into Controller... (Because I'd like to redirect to Twitter Auth Page when visitor is access specific URL without link.)

Is it possible?

When I tried it but I'm getting this error.

Zend\Mvc\Controller\PluginManager::get was unable to fetch or create an instance for hybridauthinfo

Thanks in advance!


Solution

  • You're trying to use a ViewHelper inside a controller. This is possible, you can get and use that helper instance via ViewHelperManager like this:

    $helper = $this->getServiceLocator()->get('ViewHelperManager')->get('hybridauthinfo');
    $result = $helper->__invoke();
    

    But this wouldn't be a good approach for most cases. You may want to read about Controller Plugins for controller level requirements.