gahdwaf
好问题
/** * @inheritdoc * @param int|string $id */ public static function findIdentity($id) { return static::findOne($id); } /** * @inheritdoc * @param mixed $token * @param null $type */ public static function findIdentityByAccessToken($token, $type = null) { return static::find() ->where(['=', 'token', $token]) ->one(); } /** * @inheritdoc */ public function getId() { return $this->id; } /** * @inheritdoc */ public function getAuthKey() { return $this->auth_key; }
直接在
advanced
版本中使用./init
命令切换环境。区分环境有如下常量:
YII_ENV
、YII_ENV_TEST
、YII_ENV_DEV
………………主键id不用放在rules里,既然都是主键了由数据库自己去处理就行。
- gahdwaf 回答了问题 如何安装 Fecshop?
.....楼主这是在推广自己的开源产品啊 ^_^
前者耦合度更低一些,比如想临时用某个行为可写在配置里,随用随走
- gahdwaf 回答了问题 大家感觉 yii2-redis 好用吗?
用
php-redis
扩展 采用
$model
的rules
来验证不会慢,除非你有数据库表之类耗费性能的判断,比如unique
规则示例:
<?php $inserts=[ [ 'test',177, ], [ 'test2',117, ], ... ]; $model = new TestModel(); foreach($inserts as $insert){ $model->name = $insert[0]; $model->height = $insert[1]; if(!$model->validate()){ throw new \Exception('invalid data'); } } $columns = ['name','height']; \Yii::$app->db ->createCommand() ->batchInsert('table',$columns,$inserts) ->execute();
@wsd15321
model
规则是否对数据库进行查询取决于你用的是什么规则,而不是什么每行都对数据库进行查询
,建议你自己查看debug
栏中的db
选项,一试便知。