2015-12-16 95 views
1

我使用urlManager的createAbsoluteUrl方法來生成一個URL來查看消息ID的消息模型的實例。yii2高級2.06 createAbsoluteUrl

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

這generates- http://localhost/advancedyii2/frontend/web/index.php?r=message#

但是,我要求 - http://localhost/advancedyii2/frontend/web/index.php?r=message%2Fview&id=1

你能找出問題所在?

感謝, PF

+0

show you config/main.php組件urlManager – scaisEdge

回答

0

你需要寫你的規則在你的網址: URL管理規則配置在web.php

'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', 
      ), 
    ], 
], 

您可以自定義的網址,你需要的任何方式。 More information