views:

481

answers:

0

I'm working on a multilingual site using the new Zend Framework (1.8), but I'm running into some trouble with the URL routing. It might be that I interpreted its meaning incorrectly, but well, never too late to learn. So, what's basically happening:

The site consists of several parts, e.g. 'devices' and 'articles'. The plan is to form the URL's like this: example.com/en/devices/some-page, or example.com/nl/devices/some-other-page. To achieve this, I made chained routes. Working fine so far. However, I want the home page for the 'devices' section to be like example.com/en/devices/, so without a specified page name (pretty conventional, I guess?). This is where the trouble starts. Zend trims the trailing slash off the path, so it seems to 'end' here. The Zend Documentation tells me to do something like this (routes are loaded from an XML config file):

<?xml version="1.0"?> 
<routes>
    <language type="Zend_Controller_Router_Route">
     <route>:language</route>
     <reqs language="[a-z]{2}"/>
     <defaults language="en"/>
     <chains>
      <articles type="Zend_Controller_Router_Route">
       <route>articles</route>
       <defaults controller="page" action="show" key="home-articles" />
       <chains>
        <index type="Zend_Controller_Router_Route">
         <route></route>
         <defaults controller="page" action="show"/>
        </index>
        <page type="Zend_Controller_Router_Route">
         <route>:key</route>
         <defaults controller="page" action="show"/>
        </page>
       </chains>
      </articles>
     </chains>
    </language>
</routes>

But, as often with the ZFDocs, they don't seem to be accurate (over there, the <reqs> tag isn't even closed... ouch). The URI 'en/articles/' is NOT matched to the language-articles-index route, as the trailing slash is trimmed and 'articles' is seen as the last "item" of the series, which results in a mismatch.

It is, of course, easy to find a workaround (specify two different routes - one 'terminal one', and one that continues to the page key), but if the docs tell me the previously shown approach should work, then I guess there's some kind of truth to it.

Also, I was thinking... Adding the trailing slash indicates you're trying to access the directory, while omitting it means you're looking for the resource. It doesn't apply directly to rewritten URLs, but I always thought it was good practice to simulate static directory structures - when navigating to a normal page, you're accessing a resource, but when navigating to a separate part of a site, you'll probably end up in another directory, loading the index file. Acting like every page resides in its own directory seems crazy to me. So, regular pages should be reached in this way, which is probably why Zend trims the trailing slash. However, navigating to example.com/articles/ would mean I'm trying to access the home page of the articles section. Is there a way to let ZF know that the trailing slash is there for a reason in this case?

Hope someone can make me a little (or a lot) smarter again today!