Message from discussion
Please help me understand URL and Routes in Cake
Received: by 10.36.23.3 with SMTP id 3mr3043550nzw.1172678238365;
Wed, 28 Feb 2007 07:57:18 -0800 (PST)
Return-Path: <ch...@chris-lamb.co.uk>
Received: from chris-lamb.co.uk (chris-lamb.co.uk [65.99.194.200])
by mx.google.com with ESMTP id h49si1774572nzf.2007.02.28.07.57.13;
Wed, 28 Feb 2007 07:57:18 -0800 (PST)
Received-SPF: pass (google.com: best guess record for domain of ch...@chris-lamb.co.uk designates 65.99.194.200 as permitted sender)
Received: from localhost (localhost [127.0.0.1])
by chris-lamb.co.uk (Postfix) with ESMTP id 86AAC48D16
for <cake-php@googlegroups.com>; Wed, 28 Feb 2007 15:57:13 +0000 (UTC)
Received: from chris-lamb.co.uk ([127.0.0.1])
by localhost (chris-lamb.co.uk [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 25035-07 for <cake-php@googlegroups.com>;
Wed, 28 Feb 2007 15:57:07 +0000 (UTC)
Received: from localhost.localdomain (84-12-165-61.dyn.gotadsl.co.uk [84.12.165.61])
by chris-lamb.co.uk (Postfix) with ESMTP id 67B2E48C9B
for <cake-php@googlegroups.com>; Wed, 28 Feb 2007 15:57:06 +0000 (UTC)
Date: Wed, 28 Feb 2007 15:54:36 +0000
From: Chris Lamb <ch...@chris-lamb.co.uk>
To: cake-php@googlegroups.com
Subject: Re: Please help me understand URL and Routes in Cake
Message-ID: <20070228155436.145ba5dc@localhost.localdomain>
In-Reply-To: <1172655471.192252.93610@v33g2000cwv.googlegroups.com>
References: <1172655471.192252.93610@v33g2000cwv.googlegroups.com>
X-Mailer: Sylpheed-Claws 2.5.6 (GTK+ 2.8.20; i486-pc-linux-gnu)
Mime-Version: 1.0
Content-Type: multipart/signed; boundary="Sig_=sLEGZ/UczRQE0VWJ_U2XPK";
protocol="application/pgp-signature"; micalg=PGP-SHA1
--Sig_=sLEGZ/UczRQE0VWJ_U2XPK
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable
> I understand that Cake does [routing] this in two phases, one
> using apache mod rewrite to pass the rest of the path to cake and the
> second one by "Routes" to further route the URL in cake internally. Is
> this correct?
Yes.
> I assume that the major purpose of the Routes is to map URLs to
> controllers, functions and parameters.
Correct.
> 1. I've seen a colon (:) used in the manual in routes config (like /
> blog/:action/* ). What is the special meaning of the colon? It isn't
> mentioned anywhere.
They are to control the parameters that are passed to the Controller.
I think the syntax is a Ruby-ism. First, the general case. If your
route is:
/blog/:spam/*=20
then if the browser requested
/blog/eggs/
then $this->params['spam'] would contain the value 'eggs'. You can have
more than one in the route. For example:
/blog/:year/:month/:day/:slug/*
gets you something like the default WordPress blog link structure.
There are two 'magic' parameters, "controller" and "action" which, when
set, decide which controller or action to call respectively. For
example, the route:
/blog/:action/:spam
when called with:
/blog/view/eggs/
will call the "view" action with $this->params['spam'] set to "eggs".
> 2. Can I use regular expressions in Routes like on mod rewrite? How?
> The manual doesn't mention it.
Just use regular Perl-compatible regexs.
> 3. Can I still use URL query string parameters using "?" ? Or does
> cake only use the /controller/action/param/param... convention?
Cake has a different method of handling query string parameters. My
advice is to construct a controller action to display $this->params and
see how they are handled.
> Hope I am making myself clear. Sorry for the long message.
Hopefully someone else can help with the rest if the above does not
help you solve the problem yourself. Note that the CakePHP source is
very readable for a PHP program, so examining the dispatcher code may
make sense than any of this.
Best wishes,
--=20
Chris Lamb, Leamington Spa, UK GPG: 0x634F9A20
--Sig_=sLEGZ/UczRQE0VWJ_U2XPK
Content-Type: application/pgp-signature; name=signature.asc
Content-Disposition: attachment; filename=signature.asc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
iD8DBQFF5aXC5/8uW2NPmiARArabAJ9G+PJRO3cfpnr1q+Bp3VvO7nZ1JQCfSm2/
0owJhOyfIiyNebpN9zIqTK0=
=GnhN
-----END PGP SIGNATURE-----
--Sig_=sLEGZ/UczRQE0VWJ_U2XPK--