【问题标题】:Error in activerecord query Yii2activerecord 查询 Yii2 出错
【发布时间】:2017-07-14 15:17:47
【问题描述】:

我声明:

$query = Country::find();

有效:

$countries = $query->orderBy('name')
->offset($pagination->offset)
->limit($pagination->limit)
->all();

这不起作用:

$countries = $query->orderBy('name')
->all();

PHP 警告 – yii\base\ErrorException htmlspecialchars() 期望 参数1为字符串,给定数组

有效:

$countries = $query->where(['country.code' => 'AU'])->count();

这不起作用:

$countries = $query->where(['country.population' > 4444444])->all();

无效参数 – yii\base\InvalidParamException 运算符 '' 需要两个操作数。

我阅读了https://github.com/yiisoft/yii2/blob/master/docs/guide/db-active-record.md,但我还不能完全理解这个想法

【问题讨论】:

    标签: activerecord yii2


    【解决方案1】:

    第一个“不工作”查询看起来不错,请在此错误中使用堆栈跟踪更新问题。

    第二:

    $countries = $query->where(['country.population' > 4444444])->all();
    

    您在此处使用>,将其更改为=>,它将起作用。如果你想检查这个字段是否大于/小于,你必须像 3 参数数组一样传递它:

    $countries = $query->where(['>', 'country.population', 4444444])->all();
    

    【讨论】:

      猜你喜欢
      • 2017-10-09
      • 1970-01-01
      • 1970-01-01
      • 2021-01-23
      • 1970-01-01
      • 1970-01-01
      • 2015-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多