如何创建漂亮的URL?

时间:2015-07-17 07:02:09

标签: yii2 yii2-advanced-app yii-url-manager pretty-urls

如何创建这样漂亮的网址 客户/指数/金额/ 12000 /位置/中。在Yii1.1中,它默认可用。很容易启用漂亮的网址。在Yii2中,如果需要漂亮的URL我会为每个动作编写规则!!!

在Codeigniter中,您将获得index.php / controller / action / parameter1 / parameter2 / parameter3 即它没有公开动作参数变量,也没有写任何url规则!

===编辑===

如果没有定义规则,

漂亮的URL不适用于参数

下面是我的main.php

var options  = {
        title: {
            text: ''
        },
        labels: {
            enabled: false
        },  
        title: {
            text: '',
            align: 'high',
            enabled: false

        },
        subtitle: {
            text: '',
            align: 'high',
            enabled: false
        },
        /*
        xAxis: {
            tickInterval: 1,
            breaks: [{
                from: 5,
                to: 10,
                breakSize: 1
            }]
        },
        */
        legend: {
            enabled: false
        },
         yAxis: {
            gridLineWidth:1,
            lineWidth: 1,
            min: 0,
            //tickWidth: 1,
            minTickInterval:5,
            minorGridLineWidth:1,
            minorTickInterval: 0.1,
            minorTickLength: 2,
            //type: 'logarithmic',
            minorTickInterval: 5,
            //minorTickInterval: 'auto',
            //minorTickLength: 0,
            title: {
                text: '',
                //align: 'high',
                enabled: false
            },
            labels: {
                //enabled: false,
                style: {"font-size":'8px'},
                formatter: function() {
                    return this.value;
                }
            }
        },
        xAxis: {
            min: 0,
            tickmarkPlacement: 'on',
            title: {
                enabled: false
            },
            labels: {
                enabled: false
            },  
            /*gridLineColor: '#c9d5ba',
            gridLineWidth: '1',
            lineColor: '#222222',
            lineWidth: 0,*/
            categories: [1.2, 2, 3.1, 4.3, 5.1, 5.9, 6.7, 7.5, 8.3, 9.1, 9.8, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
            labels: {
                formatter: function () {
                    return '<a style="color:green" data-value="' +[this.value] + '">' +
                        this.value + '</a>';
                },
                style: {"font-size":'8px'}
            }
        },
        series: [{
            data: [5.7, 11.1, 22.2, 38.1, 51, 66.6, 83.3, 101.1, 118.6, 135.7, 150.9, 161.4, 169.2, 172.8, 176.8, 178.5, 179.7, 179.9, 180, 179.9, 179.1]//,
            //pointInterval: 500
        }]
    };

我得到了很多404,比如

192.168.1.3/~user/urshow/frontend/web/movies/movies_all 如果它会像这样,它会工作得很好 192.168.1.3/~user/urshow/frontend/web/index.php?r=/movies/movies_all

1 个答案:

答案 0 :(得分:0)

转到 config.php 并添加

'components' => [
     ...
        'urlManager' => [
        'class' => 'yii\web\UrlManager',
        'enablePrettyUrl' => true,
        'showScriptName' => false,
         ],
    ...
],