问题
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?
回答1:
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);
}
回答2:
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.
来源:https://stackoverflow.com/questions/10899376/change-the-uri-of-a-module-without-renaming-the-class-in-pyrocms