Решение:
'rules' => [
['class' => 'app\components\CarUrlRule', 'connectionID' => 'db'],
],
Код класса:
<?php
namespace app\components;
use yii\web\UrlRule;
class CarUrlRule extends UrlRule
{
public $connectionID = 'db';
public $pattern = 'car';
public $route = 'car';
public function createUrl($manager, $route, $params)
{
if ($route === 'car/index') {
if (isset($params['manufacturer'], $params['model'])) {
return $params['manufacturer'] . '/' . $params['model'];
} elseif (isset($params['manufacturer'])) {
return $params['manufacturer'];
}
}
return false; // this rule does not apply
}
public function parseRequest($manager, $request)
{
$pathInfo = $request->getPathInfo();
$segs=explode('/',$pathInfo.'/');
$data = array();
$n=count($segs);
for($i=0;$i<$n-1;$i+=2){
if($segs[$i]==='')
continue;
$value = $segs[$i+1];
if($m=preg_match_all('/\[(.*?)\]/',$segs[$i],$matches)){
$name=substr($segs[$i],0,$pos);
for($j=$m-1;$j>=0;--$j)
if($matches[1][$j]==='')
$value=array($value);
else
$value=array($matches[1][$j]=>$value);
$data[$name]=$value;
}
else
$data[$segs[$i]]=$value;
}
return ['site/index', $data];
}
}