• 安装遇到Content-Length mismatch, received 98048 bytes out of the expected 4075770报错

修改composer.json的config键值

1
2
3
4
5
6
7
8
9
"config": {
"process-timeout": 1800,
"fxp-asset" : {
"installer-paths" : {
"npm-asset-library" : "vendor/npm",
"bower-asset-library" : "vendor/bower"
}
}
},
  • 伪静态

.htaccess文件内容为

1
2
3
4
5
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1
  • ActiveRecord属性setter getter访问器
1
2
1. 属性必须不存在才能使用
2. 属性名里不能存在type,否则不会调`bug`
  • yii2相关查询写法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$find = TrainRecord::find()
// 表别名
->alias('t')
->select(['t.train_record_id', 't.task_name', 't.project_id'])
->where(['t.user_id' => $user_id])
// like查询
->andWhere(['like', 't.task_name', (string) $task_name])
->andWhere(['=', 't.status', TrainRecord::STATUS_FINISH])
// width
->with(['project' => function ($query) {
$query->alias('p')->select(['project_name']);
}]);

$find
->andWhere(['>=', 't.create_time', $time])
->andWhere(['<', 't.create_time', $time + 3600 * 24]);

$find
// join
->joinWith(['project' => function ($query) {
$query->alias('p')->select(['project_name']);
}]);
  • 模型验证bug
1
2
3
4
1. 字段为数值型tinyint
2. 验证规则只有['status', 'in', 'range' => [0,1,2]]
3. 赋值时候使用字符串'xxx'
4. save通过但是没效果