How create url tules for all url?
page/,
cat1/page/,
cat1/cat2/cat3/page/,
cat1/cat2/cat3/product/,
…
all!
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
[
//'class' => 'app\components\TrueUrlRule',
],
]
],
<?php
namespace app\components;
use yii\web\UrlRuleInterface;
use yii\base\Object;
class TrueUrlRule extends Object implements UrlRuleInterface
{
public function createUrl($manager, $route, $params)
{
/* echo 100;
if ($route === 'car/index') {
if (isset($params['manufacturer'], $params['model'])) {
return $params['manufacturer'] . '/' . $params['model'];
} elseif (isset($params['manufacturer'])) {
return $params['manufacturer'];
}
}
return false;
*/
}
public function parseRequest($manager, $request)
{
//$pathInfo = $request->getPathInfo();
// print_r( $pathInfo );
echo 111;
}
}
?>
Error
Unsupported operand types
1. in D:\OPENSERV2\OpenServer\domains\news-site2\vendor\yiisoft\yii2\web\Request.php at line 188
179180181182183184185186187188189190191192193194195196197 * @return array the first element is the route, and the second is the associated parameters.
* @throws NotFoundHttpException if the request cannot be resolved.
*/
public function resolve()
{
$result = Yii::$app->getUrlManager()->parseRequest($this);
if ($result !== false) {
list ($route, $params) = $result;
if ($this->_queryParams === null) {
$_GET = $params + $_GET; // preserve numeric keys
} else {
$this->_queryParams = $params + $this->_queryParams;
}
return [$route, $this->getQueryParams()];
}
throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
}