2

What is the best way to change the uri of a module without renaming the class. For example I'd like the blog module to show:

/blog/post-title -> /news/post-title

routes.php?

Ben
  • 4,301
  • 6
  • 37
  • 61

2 Answers2

3

First I added to the routes.php.

$route['news/([0-9]+)/([0-9]+)/([a-zA-Z0-9_-]+)'] = 'blog/$1/$2/$3';

Then to make sure the correct links I added this to the blog plugin.php.

foreach ($posts as &$post)
{
    $post->url = str_replace('blog/', 'news/', $post->url);
}
Ben
  • 4,301
  • 6
  • 37
  • 61
1

The best way is to use the routes module.

If you don't want to use it, modify the routes.php in cms/config and not in your module because it won't run under a different path.

Yan Berk
  • 14,328
  • 9
  • 55
  • 52
  • I also have to add this to the blog plugin.php to make sure the links go to the correct location. – Ben Jun 05 '12 at 16:57
  • 1
    foreach ($posts as &$post) { $post->url = str_replace('blog/', 'news/', $post->url); } – Ben Jun 05 '12 at 16:58