Last active
April 20, 2017 18:10
-
-
Save lav45/39589340e383f713842693326d07b829 to your computer and use it in GitHub Desktop.
Setting frontendUrlManager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// common/config/main.php | |
return [ | |
'components' => [ | |
'frontendUrlManager' => [ | |
'class' => 'yii\web\UrlManager', | |
'baseUrl' => '', | |
// https://github.com/LAV45/yii2-settings/tree/master/examples/ProjectConfiguration | |
//'hostInfo' => config('frontend_url', 'https://site.com'), | |
'hostInfo' => 'https://site.com', | |
'scriptUrl' => '/index.php', | |
'enablePrettyUrl' => true, | |
'showScriptName' => false, | |
'rules' => require(Yii::getAlias('@frontend/config/url_rules.php')), | |
], | |
], | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// frontend/config/main.php | |
return [ | |
'components' => [ | |
'urlManager' => [ | |
'enablePrettyUrl' => true, | |
'showScriptName' => false, | |
'rules' => require __DIR__ . '/url_rules.php', | |
], | |
], | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// backend/controllers/SiteController.php | |
namespace backend\controllers; | |
class SiteController extends Controller | |
{ | |
public function actionIndex() | |
{ | |
Yii::$app->frontendUrlManager | |
->createAbsoluteUrl(['/news/view', 'id' => 123]); // => https://site.com/news/123 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// frontend/config/url_rules.php | |
return [ | |
'news' => 'news/index', | |
'news/<id:\d+>' => 'news/view', | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment