/** {@inheritdoc} */ public function dispatch(\Zend\Stdlib\RequestInterface $request, \Zend\Stdlib\ResponseInterface $response = null) { // Fetch group with given name for actions referring to a particular group $action = $this->getEvent()->getRouteMatch()->getParam('action'); if ($action != 'index' and $action != 'add') { try { $this->_currentGroup = $this->_groupManager->getGroup($request->getQuery('name')); } catch (\RuntimeException $e) { // Group does not exist - may happen when URL has become stale. $this->flashMessenger()->addErrorMessage('The requested group does not exist.'); return $this->redirectToRoute('group', 'index'); } } return parent::dispatch($request, $response); }