?

Log in

cakephp

URL reversing.

« previous entry | next entry »
Mar. 25th, 2007 | 08:53 pm
posted by: texhapb in cakephp

As you know, there's an URL parser in cake. But we have to write all URLs by hands in "flash" messages, "redirects", views etc.

Does anyone have any suggestions how to automatize this task? This means that it should be really simple way to change site routing.

Link | Leave a comment | Share

Comments {6}

Allan Smithee

(no subject)

from: bobalien
date: Mar. 26th, 2007 10:39 pm (UTC)
Link

i'm not sure what you're trying to do - could you give an example maybe? have you looked at setting up routes?

Reply | Thread

texhapb

Example

from: texhapb
date: Mar. 27th, 2007 09:06 pm (UTC)
Link

After I set up routing I have, for example /my/controller/action/index translated to execute the given "action" of "somecontroller" with "index". Then I want to make a redirect, so I have to write redirect('/my/controller/index'); . But when I correct my route.php to to change the route to /other/controller/action/index I have to manually correct all my source to change the paths.

Reply | Parent | Thread

Allan Smithee

Re: Example

from: bobalien
date: Mar. 27th, 2007 09:16 pm (UTC)
Link

i'm really sorry, but i'm still not getting it (doh)

what's with the /my and /other ?

why don't you do your redirects to the real /controller/action instead of to a route? then no matter how you have routes configured, your redirects would work

let's say you have PostsController with a couple of standard actions, view(), index(), etc... maybe you setup a route in routes.php to route /blog/1837 to /posts/view/1837 (where 1837 would be a wildcard)... if you want to redirect to that page from maybe a CommentController, you would probably want to format your redirect as something like:

$this->redirect('/posts/view/'.$data['Post']['id']);

instead of redirecting to $this->redirect('/blog/'.$data['Post']['id']);, to prevent having to recode things throughout your app should you choose to change your routes setup

you probably shouldn't be changing your routes much anyway, since you will have to manually change everywhere you specifically access those routes, such as a redirect, just like you would have to manually fix changes to a variable name or constant; this should be something you plan out and stick to through the application

does that answer your question? i feel like i'm still misinterpreting what you're trying to do, sorry

Reply | Parent | Thread

texhapb

Re: Example

from: texhapb
date: Apr. 3rd, 2007 07:46 am (UTC)
Link

Well, this can be a solution. Also I found some things on this: http://www.thinkingphp.org/2006/08/02/bye-bye-friendly-urls/ and http://www.thinkingphp.org/2006/09/18/dessert-11-welcome-back-friendly-urls/ . I think that the last one is good!

Reply | Parent | Thread

Re: Example

from: anonymous
date: May. 17th, 2007 06:01 pm (UTC)
Link

Just use an array (ref: http://www.noswad.me.uk/MiBlog/MakingTheMostOfTheRouter)

Cheers,

AD

Reply | Parent | Thread

Re: Example

from: anonymous
date: May. 17th, 2007 06:14 pm (UTC)
Link

Ooops I forget that not everyone uses 1.2 (which you need to make that work or course) :P

Cheers,

AD

Reply | Parent | Thread