title: Phalcon routing - making route segments optional
body: <p>I have the following route added to <code>Phalcon\MVC\Router</code>:</p>
  
  <pre><code>$router = new Phalcon\Mvc\Router();
  
  $router-&gt;removeExtraSlashes(true)
      -&gt;setDefaultNamespace('My\Controllers')
      -&gt;setDefaultModule('default')
      -&gt;setDefaultController('index')
      -&gt;setDefaultAction('index');
  
  $router-&gt;add('/admin/:controller/:action/:params', [
      'module' =&gt; 'admin',
      'controller' =&gt; 1,
      'action' =&gt; 2,
      'params' =&gt; 3,
      'namespace' =&gt; 'My\Admin\Controllers'
  ])-&gt;setName('admin_module');
  </code></pre>
  
  <p>I'm handling the following URLs:</p>
  
  <ol>
  <li><p><code>/admin/foo/bar/baz</code> - works good. I get <code>admin</code> module, <code>foo</code> controller, <code>bar</code> action, <code>"baz"</code> parameter.</p></li>
  <li><p><code>/admin/foo/bar</code> - works good. I get <code>admin</code> module, <code>foo</code> controller, <code>bar</code> action.</p></li>
  <li><p><code>/admin/foo</code> - <b>does not match</b>. I expect to get <code>admin</code> module, <code>foo</code> controller, <code>index</code> action.</p></li>
  <li><p><code>/admin</code> - <b>does not match</b>. I expect to get <code>admin</code> module, <code>index</code> controller, <code>index</code> action.</p></li>
  </ol>
  
  <p>The question:</p>
  
  <p>How can I make route segments optional and default to provided default values of controller and action name. I would like to avoid defining extra routes for <code>/admin</code> and <code>/admin/:controller</code>.</p>
  
  <p>Thank you.</p>