大佬教程收集整理的这篇文章主要介绍了PHP前后端分离使用Yii Restful,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这里主要讲的是配置文件如何美化路由
'urlManager' => [ 'enablePrettyUrl' => true, 'enableStrictParsing' => true, 'showScriptName' => false, 'rules' => [ [ 'class' => 'yii\rest\UrlRule', 'controller' => [ 'cmp-user'//表示CmpUserController ], 'tokens' => [ '{iD}' => '<id:\\w+>' ], 'extraPatterns' => [ 'GET demo-log' => 'demo-log' //controller下面的 方法 使用get 或者post设置 表示调用actionDemoLog ] ] ], ],
访问时http://localhost:8080/cmp-users/demo-log 即可
项目结构
配置文件路径在
<?PHP $params = require __DIR__ . '/params.PHP'; $db = require __DIR__ . '/db.PHP'; $config = [ 'id' => 'basic', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'aliases' => [ '@bower' => '@vendor/bower-asset', '@npm' => '@vendor/npm-asset', ], 'components' => [ 'request' => [ // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation 'cookieValidationKey' => 'SodNyloCCC4Wa82WAf0TVPPIP8ED5F_L', ], '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'], ], ], ], 'db' => $db, 'urlManager' => [ 'enablePrettyUrl' => true, 'enableStrictParsing' => true, 'showScriptName' => false, 'rules' => [ [ 'class' => 'yii\rest\UrlRule', 'controller' => [ 'cmp-user'//表示CmpUserController ], 'tokens' => [ '{iD}' => '<id:\\w+>' ], 'extraPatterns' => [ 'GET demo-log' => 'demo-log' //controller下面的 方法 使用get 或者post设置 表示调用actionDemoLog ] ] ], ], ], 'params' => $params, ]; if (YII_ENV_DEV) { // configuration adjustments for 'dev' environment $config['bootstrap'][] = 'debug'; $config['modules']['debug'] = [ 'class' => 'yii\debug\Module', // uncomment the following to add your IP if you are not connecTing from localhost. //'allowedIPs' => ['127.0.0.1', '::1'], ]; $config['bootstrap'][] = 'gii'; $config['modules']['gii'] = [ 'class' => 'yii\gii\Module', // uncomment the following to add your IP if you are not connecTing from localhost. 'allowedIPs' => ['127.0.0.1', '::1','172.16.5.22'], ]; } return $config;
以上是大佬教程为你收集整理的PHP前后端分离使用Yii Restful全部内容,希望文章能够帮你解决PHP前后端分离使用Yii Restful所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。