yii2 RESTful 接口 api -4 : 单独一个应用

来源:互联网 发布:用淘宝充话费多久到账 编辑:程序博客网 时间:2024/05/22 01:57

可以类似创建frontend   backend  那样,单独创建一个api的 application

我没有单独配置这个。

参考:

http://stackoverflow.com/questions/26230517/why-create-a-separate-application-for-restful-api

https://github.com/githubjeka/yii2-rest/blob/master/rest/config/main.php

这样,在一个应用中 urlManager的配置就不会有冲突!

'urlManager' => ['class' => 'yii\web\UrlManager','enablePrettyUrl' => true,'enableStrictParsing' => true,'showScriptName' => false,'rules' => ['' => 'cms/index',['class' => 'yii\rest\UrlRule', 'controller' => 'customer/api',  'pluralize' => false,],#  定义方法: public function actionSearch($id);   <id> 就是search方法传入的参数'POST customer/api/search/<name>' => 'customer/api/search',//'POST customer' => 'customer/index/create',],],


0 0