2009年10月5日星期一

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

Hmm, I've got the following route now:

page.type = "Zend_Controller_Router_Route_Regex"
page.route = "page(\/.*)"
page.map.1 = "path"
page.reverse = "%s"
page.defaults.controller = "page"
page.defaults.action = "index"

This means that site.com/page/hello/world returns $path = '/hello/word' which is what I expected.

However,  there seems to be something wrong with the reverse function.

$this->url(array('path' => '/hello/world'), 'page') doesn't return '/page/hello/world' but just '/hello/world'.

Is this behaviour correct and if so, why?


Brenton Alker schreef:
-----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-----    

没有评论: