Coming from background of Laravel and Rails I am finding quite a difficulty to figure out how Yii2 rules work.
I am looking for following URL patterns:
- /articles/
- /articles/view/
- /articles/1/my-pretty-article
ArticlesController
is defined like:
<?php
namespace app\controllers;
class ArticlesController extends \yii\web\Controller
{
public function actionIndex()
{
return $this->render('index');
}
public function actionView()
{
return $this->render('index');
}
}
So far I have tried:
'urlManager' => [
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules' =>
[
'articles/view' => 'article/view'
],
],
I am more interested to redirect my pattern to controller@method.
It's possible to use
<id>
param:And your articles controller: