├─assets │ AppAsset.php ├─config │ bootstrap.php │ main-local.php │ main.php │ params-local.php │ params.php ├─runtime └─web │ index.php ├─assets └─css
'components' => [ // other config 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'enableStrictParsing' =>true, 'rules' => [], ] ],
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
RewriteRule \.svn\/ /404.html
RewriteRule \.git\/ /404.html
CREATE TABLE `goods` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `goods` VALUES ('1', '11111');
INSERT INTO `goods` VALUES ('2', '22222');
INSERT INTO `goods` VALUES ('3', '333');
INSERT INTO `goods` VALUES ('4', '444');
INSERT INTO `goods` VALUES ('5', '555');
│ ├─models │ Goods.php │ ├─modules │ └─v1 │ │ Module.php │ │ │ ├─controllers │ │ DefaultController.php │ │ GoodsController.php │ │ │ └─views │ └─default │ index.php
<?php
namespace api\modules\v1\controllers;
use yii\rest\ActiveController;
class GoodsController extends ActiveController
{
public $modelClass = 'api\models\Goods';
}
'rules' => [ [ 'class' => 'yii\rest\UrlRule', 'controller' => ['v1/goods'] ], ]
'components' => [ 'user' => [ 'identityClass' => 'common\models\User', 'enableAutoLogin' => true, 'enableSession'=>false ], ],
<?php
namespace api\modules\v1\controllers;
use yii\rest\ActiveController;
use yii\helpers\ArrayHelper;
use yii\filters\auth\QueryParamAuth;
class UserController extends ActiveController
{
public $modelClass = 'api\models\User';
public function behaviors() {
return ArrayHelper::merge (parent::behaviors(), [
'authenticator' => [
'class' => QueryParamAuth::className()
]
] );
}
}
public static function findIdentityByAccessToken($token, $type = null)
{
return static::findOne(['access_token' => $token, 'status' => self::STATUS_ACTIVE]);
}
{
"name": "Unauthorized",
"message": "You are requesting with an invalid credential.",
"code": 0,
"status": 401,
"type": "yii\\web\\UnauthorizedHttpException"
}
use yii\filters\RateLimitInterface;
use yii\web\IdentityInterface;
class User extends ActiveRecord implements IdentityInterface, RateLimitInterface
{
// other code ......
// 返回某一时间允许请求的最大数量,比如设置10秒内最多5次请求(小数量方便我们模拟测试)
public function getRateLimit($request, $action){
return [5, 10];
}
// 回剩余的允许的请求和相应的UNIX时间戳数 当最后一次速率限制检查时
public function loadAllowance($request, $action){
return [$this->allowance, $this->allowance_updated_at];
}
// 保存允许剩余的请求数和当前的UNIX时间戳
public function saveAllowance($request, $action, $allowance, $timestamp){
$this->allowance = $allowance;
$this->allowance_updated_at = $timestamp;
$this->save();
}
}
{
"name": "Too Many Requests",
"message": "Rate limit exceeded.",
"code": 0,
"status": 429,
"type": "yii\\web\\TooManyRequestsHttpException"
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有