2009年9月29日星期二

Re: [fw-mvc] how to use a 'recursive' route

What about using a regular route but giving it a large number of optional parts?

/page/:part1/:part2/:part3/:part4....

To make them optional, assign default values for each part.

Or you can probably make your own route class that can handle this, but I'm not too familiar with how to build custom routes.

--
Hector


On Tue, Sep 29, 2009 at 1:04 AM, Brenton Alker <brenton@tekerson.com> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dimitri van Hees wrote:
> Hi,
>
> I've searched the whole internet about this issue, but without success,
> so I'm trying it here now ;-) Imagine I have a site where a user can
> recursively add subpages. Ofcourse the user isn't able to add routes, so
> I bet I should add a 'recursive' route. This should be something like:
> */page** where *** = */userinput1/userinput2/userinput3* I assume. Then
> I think I have to handle this path myself. However, I am unable to get
> this whole path. Does anyone have a best practice for this? If I use
> *page(/\w+)+* in a regex route I am only able to retrieve the last part
> (*/userinput3*) without the preceding path. Anyone?

If you're using a regex route (you appear to be) then you can do
"page(/.*)" to get the entire url after "/page". This doesn't break it
into parts, but that should be easy to do at the application level (if
it's actually required).

I have run into a similar problem in a different context, the routing
doesn't seem to deal very well with situations where there are an
unknown number of parts.

- --

Brenton Alker
PHP Developer - Brisbane, Australia

http://blog.tekerson.com/
http://twitter.com/tekerson

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkrBv5EACgkQ7bkAtAithuvppACg3cjvAQ+eYu6kO0jzTWWgMVWc
BGMAn0zQJPaPY7/NdKD9y7AIGC+mpXgQ
=3Et8
-----END PGP SIGNATURE-----


没有评论: