在Yii中,我正在使用以下代码来生成URL
Yii::$app->urlManager->createUrl('site/delete',array('id' => 100))
它将生成如下所示的URL,并且URL中缺少参数ID
http://localhost/yii-basic/web/index.php?r=site%2Fdelete
在配置文件中,规则如下
'urlManager' => [
'enablePrettyUrl' => false,
'showScriptName' => false,
'rules' => [
'post/<id:\d+>/<title:.*?>'=>'post/view',
'posts/<tag:.*?>'=>'post/index',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
],
],
答案 0 :(得分:0)
根据the documentation,正确的语法为:
Yii::$app->urlManager->createUrl(array('site/delete', 'id' => 100));
我发现使用\yii\helpers\Url
类和短数组语法更方便:
Url::to(['site/delete', 'id' => 100]);