title: ZF2 routing and redirect function in controller
body: <p>The following problem I am facing, error look likes this;</p>
  
  <pre><code>An error occurred
  An error occurred during execution; please try again later.
  Additional information:
  Zend\Mvc\Exception\DomainException
  
  File: .../vendor/zendframework/zendframework/library/Zend/Mvc/Controller/Plugin/Url.php:63
  
  Message:
  Url plugin requires that controller event compose a router; none found
  </code></pre>
  
  <p>I never faced this problem while I am trying to redirect from my controller. Lets say I implement the following function for redirection in my controller, which produces the error above;</p>
  
  <pre><code>public function __construct()
      {   
          # Get user identity
          $auth = new AuthenticationService();        
          if ($auth-&gt;hasIdentity()) {
          $this-&gt;identity = $auth-&gt;getIdentity();
          } else {
          $this-&gt;redirect()-&gt;toRoute('admin/login');
          }
      }
  </code></pre>
  
  <p>The routing does exist as I can reach site.com/admin/login/ .. login is a child of admin so notation must be good. I am wondering what's going wrong and how to fix this issue or even, where to look for it would be a great starting point as well.</p>
  
  <p>Thanks!</p>