这里的urlManager配置:
$stmt->bindParam(':subtotal', $subTotal);
这里的urlManager使用:
return [
'class' => \yii\web\UrlManager::class,
'enablePrettyUrl' => true,
'showScriptName' => false,
'baseUrl' => '',
'rules' => [
'page/<id:[\\w-_]+>' => 'page/index',
],
];
以下是浏览器的结果:
$menuItems = [
[
'label' => 'Home',
'url' => Yii::$app->urlManager->createAbsoluteUrl(['/page']),
],
[
'label' => 'About',
'url' => Yii::$app->urlManager->createAbsoluteUrl(['/page', 'id' => 'about']),
],
[
'label' => 'Contact',
'url' => Yii::$app->urlManager->createAbsoluteUrl(['/page', 'id' => 'contact']),
],
];
http://localhost/page?id=about
我的代码有什么问题?
答案 0 :(得分:1)
创建网址时需要使用确切的路线:
$menuItems = [
[
'label' => 'Home',
'url' => Yii::$app->urlManager->createAbsoluteUrl(['/page']),
],
[
'label' => 'About',
'url' => Yii::$app->urlManager->createAbsoluteUrl(['/page/index', 'id' => 'about']),
],
[
'label' => 'Contact',
'url' => Yii::$app->urlManager->createAbsoluteUrl(['/page/index', 'id' => 'contact']),
],
];