Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Please help me understand URL and Routes in Cake

View Parsed - Show only message text

Received: by 10.114.88.1 with SMTP id l1mr139537wab.1172693640109;
        Wed, 28 Feb 2007 12:14:00 -0800 (PST)
Received: by m58g2000cwm.googlegroups.com with HTTP;
	Wed, 28 Feb 2007 20:13:58 +0000 (UTC)
X-IP: 83.245.25.235
From: "John" <johnsv...@googlemail.com>
To: "Cake PHP" <cake-php@googlegroups.com>
Subject: Re: Please help me understand URL and Routes in Cake
Date: Wed, 28 Feb 2007 12:13:58 -0800
Message-ID: <1172693638.944310.161570@m58g2000cwm.googlegroups.com>
In-Reply-To: <1172655471.192252.93610@v33g2000cwv.googlegroups.com>
References: <1172655471.192252.93610@v33g2000cwv.googlegroups.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.1),gzip(gfe),gzip(gfe)
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1


> So, I'd like to have the following URLs
> /units    - for a view showing a table of multiple units
> /units/<unit name>    - for a view of the single unit (no, I don't
> want to use the action in the URL like /units/view/<unit name>, I'd
> like to keep this one as short and simple as possible)

I wanted to do something similar, but rather than using routes I put a
condition in the beforeFilter of a controller. The controller is
called galleries, I wanted to keep the actions like index, view,
detail, etc. So I could have /galleries/view/<gallery id> but also to
have /galleries/<region name>

Anyway I've got the following in my controller

var $regions = array('london', 'south_west', 'north', 'south_east',
'central', 'wales', 'scotland', 'northern_ireland');

function beforeFilter()
{
if(in_array($this->action, $this->regions))
  {
     $this->region();
     exit;
  }
}

So if the is a URL like /galleries/london it will route to the the
action region() in the controller.

It works well, but I was wondering if there are better solutions?




Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google