Yii2:如何用use调用url中的action";漂亮的url”;


Yii2: how to call action in url with use "pretty url"

如果没有漂亮的url,路由具有视图http://192.168.100.5/index.php?r=tweet/statistic&from=20160320&to=20160325,并且运行良好。

正如文档所说,当'enablePrettyUrl' => true /tweet调用默认操作时,它也能很好地工作

但对于其他动作,路由应该是/tweet/statistic。但是有404错误。

在这种情况下,我如何调用app''controllers''TweetController actionStatistics()?

添加:我使用基本模板

'urlManager' => [
    'enablePrettyUrl' => true,
    'enableStrictParsing' => true,
    'showScriptName' => false,
    'rules' => [
        ['class' => 'yii'rest'UrlRule',
         'controller' => 'tweet'],
        'GET tweet/statistic' => 'tweet/statistic'
    ],
],

当我尝试http://192.168.100.5/tweet/statistic 的卷曲请求时

HTTP/1.1 404找不到

如果'enablePrettyUrl' => falsehttp://192.168.100.5/index.php?r=tweet/statistic"工作良好,

请注意,这是一个rest API,因为这会改变很多事情。重点是你必须声明规则,这样Yii2现在就知道如何处理它们了。你必须告诉它这将是什么类型的请求,以及请求将去哪里。与普通应用程序相比,这是非常不同的,因为这是一个rest API。

我的工作配置:

 'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => [
                [
                    'class' => 'yii'rest'UrlRule',
                    'controller' => [
                        'v1/client',
..........................
                    ]
                ],
                'GET v1/clients/info' => 'v1/client/info',
                'POST v1/settings/suburb' => 'v1/setting/suburb',
            ],
        ],