Php yii2高级2.06 createAbsoluteUrl

Php yii2高级2.06 createAbsoluteUrl,php,yii2,yii2-advanced-app,Php,Yii2,Yii2 Advanced App,我正在使用urlManager的createAbsoluteUrl方法来生成一个URL,以按消息ID查看消息模型的实例 Yii::$app->urlManager->createAbsoluteUrl(['/message/view', 'id'=>$model->id, '#' => $model->id]) 这就产生了- 但是,我需要- 你能找出问题所在吗 谢谢, pf您需要将url规则写入: web.php中的URL管理器规则配置 'compone

我正在使用urlManager的createAbsoluteUrl方法来生成一个URL,以按消息ID查看消息模型的实例

Yii::$app->urlManager->createAbsoluteUrl(['/message/view', 'id'=>$model->id, '#' => $model->id])
这就产生了-

但是,我需要-

你能找出问题所在吗

谢谢,
pf

您需要将url规则写入: web.php中的URL管理器规则配置

'components' => [
    'urlManager' => [               
        'showScriptName' => false,  // Disable index.php
        'enablePrettyUrl' => false, // Disable r= routes
        'enableStrictParsing' => true,
        'rules' => array(
                'mycategory/<controller:\w+>/<action:\w+>' => '<controller>/<action>',
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
                //Rules with Server Names
                'http://admin.domain.com/login' => 'admin/user/login',
                'http://www.domain.com/login' => 'site/login',
                'http://<country:\w+>.domain.com/profile' => 'user/view',
                '<controller:\w+>/<id:\d+>-<slug:[A-Za-z0-9 -_.]+>' => '<controller>/view',
            ),
    ],
],
“组件”=>[
“urlManager”=>[
'showScriptName'=>false,//禁用index.php
'enablePrettyUrl'=>false,//禁用r=routes
'enableStrictParsing'=>true,
'规则'=>数组(

'mycategory/

您需要将url规则写入: web.php中的URL管理器规则配置

'components' => [
    'urlManager' => [               
        'showScriptName' => false,  // Disable index.php
        'enablePrettyUrl' => false, // Disable r= routes
        'enableStrictParsing' => true,
        'rules' => array(
                'mycategory/<controller:\w+>/<action:\w+>' => '<controller>/<action>',
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
                //Rules with Server Names
                'http://admin.domain.com/login' => 'admin/user/login',
                'http://www.domain.com/login' => 'site/login',
                'http://<country:\w+>.domain.com/profile' => 'user/view',
                '<controller:\w+>/<id:\d+>-<slug:[A-Za-z0-9 -_.]+>' => '<controller>/view',
            ),
    ],
],
“组件”=>[
“urlManager”=>[
'showScriptName'=>false,//禁用index.php
'enablePrettyUrl'=>false,//禁用r=routes
'enableStrictParsing'=>true,
'规则'=>数组(

'mycategory/

显示配置/main.php组件urlManager显示配置/main.php组件urlManager