[CakePHP] alias in the url

The task was to have “aliases” for url. For example let’s think about a ProjectsController; each project is characterized by a unique id, a unique name and some other attributes. With the cake way you can refer to the projects with /projects/add, /projects/edit/$id, /projects/delete/$id and /projects/view/$id.

I would like to have an alias for the view: call each project even with a url like /projects/$name (friendlier url).

I achieved the task extending the ErrorHandler::missingAction(). Here is the code I used (pdf).

I don’t know if this is the proper way to do this but it’s working.

2 comments so far

  1. [...] web ·Tagged alias, cakephp, php, programming, url, web Some days ago, I posted about having dynamic URL aliases with cake-php 1.1.18. In that post I used the AppError object trapping the missingAction [...]

  2. Wharfage on

    Somehow i missed the point. Probably lost in translation :) Anyway … nice blog to visit.

    cheers, Wharfage.


Leave a reply