Coder1
Aricles and Screencasts by Mike Milano
Today is: 21 November, 2008
Check todays hot topics or new pictures
Aricles and Screencasts by Mike Milano
Today is: 21 November, 2008
Check todays hot topics or new pictures
An alternative to Pathauto
custom_url_rewrite is a function (not a hook) available in Drupal which gives you an alternative to configuring custom paths and storing them in the database. Since this is not a hook, it is suggested you put this in settings.php. You can convert the alias into the source, and vice versa. There's a great code example in the API link above which shows a few examples of what you can do with this function including changing 'node/' to 'article/' and changing the user's profile page from 'user/1' to 'e'. I'll take it a step further and demonstrate how to change 'node/1' to something like 'stories/1-my-big-long-story-title'. You can use preg_match to find a node id and query for the node type and title. Based on the type, you could then incorporate the title into the url for the 'alias' operation. In the 'source' operation, you could then use preg_match again to change the request back to 'node/' without even having to add an item to the menu hook. This exact code isn't tested, but it would look something like this:
You need to consider that this function is going to be called anytime l() or url() are called, so you could seriously put a lot more load on the server if you have anything too heavy in there. |
|||
|
Copyright © 2008, Mike Milano
|
Post new comment