Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm afraid you're going to need to rethink your URL scheme a little, or change the way your routes are setup, as you've hit two limitations of the way ZF's routing works.</p> <p>The first is that the router has no knowledge of what is or isn't a valid module, controller or action; all it does is match the strings in the URL to variables in the route. It does this by checking each route in succession, in reverse order, until it finds a match. When you hit <code>/en/controller</code>, it first checks your <code>/:lang</code> route, which won't match. It then checks <code>/:lang/:module</code>, which will match, because <code>/:lang/:module</code> will match /anything/anything unless you tell it otherwise.</p> <p>With that in mind you won't be able to have both:</p> <pre><code>/en/controller /en/action </code></pre> <p>unless you set some restrictions, as a URL like <code>/en/foo</code> will always be matched by whichever of the two you define last.</p> <p>If you have a fairly small number of actions/controllers that don't often change, the simplest way around this is to hardcode in some possible values for the 2nd of the two routes, e.g.:</p> <pre><code>$router-&gt;addRoute('langmod', new Zend_Controller_Router_Route( '/:lang/:module', array( 'lang' =&gt; ':lang', 'action' =&gt; 'index', 'controller' =&gt; 'index' ), array( 'module' =&gt; '(foo|bar|something)' ) )); </code></pre> <p>replace foo, bar etc. with valid module names. Now when you hit <code>/en/controller1</code> it won't match this route because controller1 doesn't match the regexp pattern defined for the :module variable. You would then need a separate <code>/:lang/:controller</code> route (or possibly <code>/:lang/:controller/:action</code>) for it to match instead.</p> <p>You asked how you set a default value for some of the variables. You are actually already doing this with the action in a few of your routes, but for controller/module won't quite work in the way you are hoping. If we take your langmodcontroller route and change it to this:</p> <pre><code>$router-&gt;addRoute('langmodcontroller',new Zend_Controller_Router_Route( '/:lang/:module/:controller', array( 'lang' =&gt; ':lang', 'controller' =&gt; 'index' 'action' =&gt; 'index' ) )); </code></pre> <p>there's now a default value for the controller variable. If we pretend for a second that this was the only route, a request for <code>/en/blog</code> would now get matched by this and set the request params to lang = en, module = blog, controller = index, action = index. <code>/en/blog/index/foo</code> would also match this route, and would give you module = blog, controller = index, action = foo. But note that even though controller = index you still need that in the URL. So limitation number two is that you always need the variable in the URL (even if it is set to your default) as long as you have something after it that isn't the default.</p> <p>With these limitations in mind I'd suggest you go with something like this (defined in this order):</p> <pre><code>/:lang/:controller/:action/ (with 'index' defaults for controller and action) /:lang/:action (with 'action' restricted to some predefined values) /:lang/admin/:controller/:action (with 'admin' as a string in the URL, and :module set to 'admin' as the default) </code></pre> <p>This would give you URLs like this:</p> <pre><code>/en /en/controller /en/controller/action /en/action /en/controller/param /en/admin/controller /en/admin/controller/action </code></pre> <p>which is pretty much what you are after. </p> <p>The routing in ZF is very powerful, you just need to know its quirks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload