Hi Larry,
Actually, it was a little bit of frustration. Simply speaking - routing rules are confusing and available explanations not comprehensive.
As I already bought your "Yii Book" a few days ago - I tried to find some info right there and... nope. Very little clues on the subject for the time being.
My problem has started with hangling static pages in Yii.
As you know, default site controller handle static pages through statically assigning "page" action to CViewAction class. This class render a view file residing in "site/page" folder and the name of the file is provided as query string: http://mydomain/index.php?r=site/page&view=FileName.
Well - I am unable to find a good routing rule what would convert such an URL into something more SEO friendly like: http://mydomain/site/page/FileName. No way - nothing works!
OK - there are some solutions descripted on Yii forums but they all require to manually specify routing rule for each and every static page on the website. This is nonsense.
So, finally I found a workaround, but I am unsure is it an "elegant" one:
Simply speaking, I consider static pages are pages what are actually served "as they are" - so no specific controller action is necessary to to serve them. Consequently - they can be served by the "missingAction" handler. So I have decided to create a new StaticController like this:
class StaticController extends Controller
{
public function missingAction($actionID)
{
if(file_exists($this->getViewPath() . '/' . $actionID . '.php')){
$this->render($actionID);
}else{
throw new CHttpException(404, 'Page not found!');
}
}
}
And this controller can serve any view file residing in "/static" folder by its name. If given page is not found - proper exception is thrown. Consequently - there is no need to update anything while new static page is added. This is working nice but the only problem is... Menu item is not highlighted with given static page is displayed... Perhaps you can provide better solution?
Best regards,
Ziggi