金色木叶枫 2015-01-29 13:11:53 7753次浏览 0条评论 2 0 0

Yii2 Url Management 使用介绍

简约简单不说废话直接上代码了

'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => '$2y$13$XV1Vbasx6Gib7ujOZwlzq.auFh0BIi.aDekM4TTMQl0bnV1PQAHMK',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
      'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [

            ],
        ],

弄完上面的配置文件之后,首先确保 apache 服务器配置好了 Rewrite 规则,Yii2 推荐的apache配置如下可能还要加个.htaccess文件,代码如下

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

好的到此我们的配置就ok了,可以愉快的去看看url的显示!

原文链接地址

    没有找到数据。
您需要登录后才可以评论。登录 | 立即注册