I'm migrating a site to 2.x and have run into some problems with
routing. URLs for the site are preceded by a 2-letter code for
language. My routes.php begins:

$lang_regexp = implode('|', Configure::read('Config.languages'));

Router::connect(
        '/',
        array('controller' => 'languages', 'action' => 'choose')
);

// eg. routes like /en or /fr
Router::connect(
        '/:lang',
        array('controller' => 'volumes', 'action' => 'current'),
        array(
                'lang' => $lang_regexp,
        )
);

So, an empty URL is directed to the LanguagesController, which decides
where to redirect:

public function choose()
{
        $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
        
        if (empty($lang) || !in_array($lang, 
Configure::read('Config.languages')))
        {
                /* assign first in list
                 */
                $lang = array_shift(Configure::read('Config.languages'));
        }
        
        //die(debug(Router::parse("/${lang}")));
        $this->_setLanguage($lang);
        $this->redirect(Router::parse("/${lang}"));
}

If I uncomment the die() call, I see:

Array
(
    [lang] => en
    [named] => Array
        (
        )

    [pass] => Array
        (
        )

    [controller] => volumes
    [action] => current
    [plugin] =>
)

This appears to be correctly parsed. However, the redirects goes to:
/volumes/current/lang:en

This does display the correct page, but it's not what I want.

If I manually enter "/en" I also get the correct page. Entering "/fr"
likewise, with the language settings likewise correctly handled.

So, why is Router::parse() working, but the redirect (sort of) not?
This was working flawlessly with 1.3 so I assume it's due to a change
somewhere. Default routing is enabled, but comes at the end of
routes.php (disabling it leads to missing controller errors having to
do with loaded elements, apparently).

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to