yii2 使用记录

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

修改composer.json的config键值

"config": {
    "process-timeout": 1800,
    "fxp-asset" : {
        "installer-paths" : {
            "npm-asset-library" : "vendor/npm",
            "bower-asset-library" : "vendor/bower"
        }
    }
},
  • 伪静态

.htaccess文件内容为

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1
  • ActiveRecord属性setter getter访问器

  • 属性必须不存在才能使用
  • 属性名里不能存在type,否则不会调bug

  • yii2相关查询写法

    $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

  • 字段为数值型tinyint
  • 验证规则只有['status', 'in', 'range' => [0,1,2]]
  • 赋值时候使用字符串'xxx'
  • save通过但是没效果

相关文章

此处评论已关闭