月度归档:2018年09月

Yii2生成前台URL链接

1.配置

'urlManagerFrontend' => [
            'class'               => 'yii\web\UrlManager',
            'hostInfo'            => $params['domain']['frontend'],//http://www.test.com
            'enablePrettyUrl'     => true,
            'showScriptName'      => false,
            'enableStrictParsing' => false,
            'rules'               => [],
        ],

2.view中使用

echo   Yii::$app->urlManagerFrontend->createAbsoluteUrl(['mobile/store/index','id'=>101]);
//http://www.test.com/mobile/store/index?id=101
0

Yii2设置URL美化(Apache)

1.在对应模块下的web目录下创建.htaccess文件,输入以下代码:

RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php

2.修改配置文件

'components' => [
    // ...
    'urlManager' => [
        'class' => 'yii\web\UrlManager',
        // Hide index.php
        'showScriptName' => false,
        // Use pretty URLs
        'enablePrettyUrl' => true,
        'rules' => [
        ],
    ],
    // ...
],
0