php - Make a controller indexcontroller in yii -
i planning make blog in yii. have table named article , corresponding model,view,contoller generated using gii. want posts displayed in home page set
defaultcontroller='article'
although posts displayed in homepage, when click title readmore, url still has contoller name in like
www.yiisite.com/article/1
so want url instead:
www.yiisite.com/1
i want hide controller name in url.
what conventional method implement it?
i wanted make url seo friendly used following rule:
'/<year:\d{4}>/<month:\d{2}/<vanity:[\w\w]+>'=>'article/view'
now in loadmodel() in articlecontroller wish change findbypk($id) fetch data using year,month , unique vanity url. url www.yiisite.com/2013/07/vanity-url-article.
this approach fine right?
update urlmanager
on site config
return array( 'name'=>'my project', 'defaultcontroller'=>'article', 'components'=>array( 'urlmanager'=>array( 'urlformat'=>'path', 'casesensitive' =>true, 'showscriptname'=>false, //'usestrictparsing'=>true, 'rules'=>array( '<action:[\w\-]+>' => 'article/<action>', ), ), ), );
Comments
Post a Comment