Using regular expressions in URL rules
One of the hidden features of the Yii URL router is that you can use regular expressions that are pretty powerful for handling strings.
Getting ready
Create a new application using the Composer package manager, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html.
In your
@app/controllers
directory, createPostController.php
using the following:<?php namespace app\controllers; use yii\helpers\Html; use yii\web\Controller; class PostController extends Controller { public function actionView($alias) { return $this->renderContent(Html::tag('h2', 'Showing post with alias ' . Html::encode($alias) )); } public function actionIndex($type = 'posts', $order = 'DESC') { return $this->renderContent(Html::tag('h2', 'Showing ' . Html::encode($type) . ' ordered ' . Html::encode($order) )); } public function actionHello($name...