kalopsia
(Hangglide Only)
February 16, 2014, 9:49am
1
I’ve read the related topic in Yii 1.x discussions (Default Controller for root), but unfortunately the author havn’t found any solution. So I ask again.
How can I create pages: feedback.php, about.php etc in a view folder of custom controller/site controller and then access them by going to site.com/feedback , site.com/about etc without adding actions and rules for each one?
samdark
(Alexander Makarov)
February 16, 2014, 11:03am
2
Add the last rule like:
'<page>' => 'site/page',
You’ll lose ability not to specify routes for each controller action though.
kalopsia
(Hangglide Only)
February 16, 2014, 12:15pm
3
If I understand correctly the sentence above means:
Тебе не придется указывать роуты для последующих экшенов контроллера. Или слово though в конце предложения говорит о каком-то подводном камне?
Did I understand correctly?
Sorry for the russian injections, but my english isn’t allow me to talk on the level at which you speak.
kalopsia
(Hangglide Only)
February 16, 2014, 12:19pm
4
By the way. The code below use Yii 1 to specify action for rendering static pages under views/site/page folder:
'page'=>array(
'class'=>'CViewAction',
'defaultView'=>'about',
'basePath'=>'pages',
),
);
How can I implement the same in Yii 2?
samdark
(Alexander Makarov)
February 16, 2014, 6:18pm
5
Придётся прописывать роуты вообще для всего потому как такое правило отключает все умолчания.
Page rendering is easy:
public function actionPage($view = 'index')
{
try {
return $this->render('site/page/' . $view);
} catch (InvalidParamException $e) {
throw new HttpException(404);
}
}
kalopsia
(Hangglide Only)
February 20, 2014, 2:20pm
6
hm…not bad! Thank you! I think this moment must be documented somewhere to prevent newbie difficulties…