Skip to content

Instantly share code, notes, and snippets.

@dshafik
Created June 23, 2013 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dshafik/5843549 to your computer and use it in GitHub Desktop.
Save dshafik/5843549 to your computer and use it in GitHub Desktop.
Add success message to ZfcUser without modifying the ZfcUser code in any way
<?php
namespace Application;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
class Module {
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$serviceManager = $e->getApplication()->getServiceManager(); // Get the ServiceManager
$viewHelperManager = $serviceManager->get('ViewHelperManager'); // This is how we will access the FlashMessenger view helper
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$events = $eventManager->getSharedManager();
$events->attach(
'ZfcUser\Authentication\Adapter\AdapterChain', // Plugin to the Authentication chain event manager
'authenticate', // and hook into the authentication event
function ($e) use ($viewHelperManager) { // pass in the ViewHelperManager
/* @var $messenger \Zend\View\Helper\FlashMessenger */
$messenger = $viewHelperManager->get('flashmessenger'); // Get the flashmessenger view helper
$messenger->getPluginFlashMessenger()->addSuccessMessage("Successfully Logged In!"); // Add the success message
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment