Overwrite url method in your app_helper.php. Here's what I've done for
keeping language in my urls:

class AppHelper extends Helper {
        function url($url = null, $full = false) {
                if (is_array($url)) {
                        $default = Configure::read('Config.defaultLanguage');
                        if (empty($url['lang']) && isset($this->params['lang']) 
&& $this-
>params['lang'] != $default) {
                                $url['lang'] = $this->params['lang'];
                        } elseif (isset($url['lang']) && $url['lang'] == 
$default) {
                                unset($url['lang']);
                        }
                }
                return parent::url($url, $full);
        }
}

class AppController .....
        function redirect($url, $status = null, $exit = true) {
                if (is_array($url)) {
                        if (empty($url['lang']) && isset($this->params['lang']) 
&& $this-
>params['lang'] != Configure::read('Config.defaultLanguage')) {
                                $url['lang'] = $this->params['lang'];
                        } elseif (isset($url['lang']) && $url['lang'] ==
Configure::read('Config.defaultLanguage')) {
                                unset($url['lang']);
                        }
                }
                return parent::redirect($url, $status, $exit);
        }

        function beforeFilter() {
                if (empty($this->params['lang'])) {
                        $this->params['lang'] = 
Configure::read('Config.defaultLanguage');
                }
        }

This will put language param into all generated urls but for the
default one (I don't want language prefix for default language -
Shorter urls = better SEO)

Hope this helps.


On Jul 8, 10:20 am, sam <[EMAIL PROTECTED]> wrote:
> The thing is: I actually want the parameter in my URL, since it is
> significant to the user -- so storing it in the session is really not
> an option. I'd rather not rely on sessions (and thus enabled Cookies)
> for a critical part of the application anyway. (Of course, login/
> logout is critical too and does require a Cookie, but you can expect
> users to activate them if they need to authenticate for a specific
> task).
>
> So if there is no automated way, I'll probably solve it by adding a
> method __link() to my controller that adds the "layout" argument to
> any array passed and that I call wherever a link needs to be built.
>
> However, if anyone can suggest a better strategy I'll be happy to
> consider it.
>
> On 8 Jul., 04:31, "b logica" <[EMAIL PROTECTED]> wrote:
>
> > You could store it in the session and have your controllers check that
> > in beforeFilter(). Or, rather, check to see if it's in $this->params
> > first, then session, and finally have a default to fall back on.
>
> > On Mon, Jul 7, 2008 at 5:52 AM, sam <[EMAIL PROTECTED]> wrote:
>
> > > Dear Cake pros,
>
> > > I have a route that allows me to switch the layout by supplying it as
> > > the first parameter in de URI. Example for using the "green" layout:
>
> > >http://myhost/green/items/index
>
> > > Here's the route:
>
> > > Router::connect('/:layout/:controller/:action/*', array('controller'
> > > => 'items', 'action' => 'index') ,array('layout' => 'red|green'));
>
> > > Now, I would like my controllers to propagate the "layout" parameter
> > > automatically, without requiring me to code this manually wherever I
> > > create a link or redirect to a page. Is this possible?
>
> > > If not, what would be the best way to achieve this?
>
> > > Thank you very much.
> > > Sam
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to