属性“CDbCriteria.:centerId”未在yii中定义

e7arh2l6  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(144)

我在yii中使用select方法,它给出错误“属性“CDbCriteria.:centerId”未定义”

if (0 < self::model()->countByAttributes(
    'centerId = :centerId AND qTypeId = :qTypeId',
    array(
        ':centerId' => $centerId,
        ':qTypeId'  => $qTypeId,
    )
)) {
    throw new Exception('Duplicate Entry for center and que type');
}
6g8kf2rb

6g8kf2rb1#

您使用此方法的方式不正确。您跳过了第一个参数,该参数应该是用作筛选器的活动记录参数的列表(请参阅文档)。您可能需要类似以下的内容:

if (0 < self::model()->countByAttributes([
    'centerId' => $centerId,
    'qTypeId'  => $qTypeId,
]) {
    throw new Exception('Duplicate Entry for center and que type');
}

或者使用count()

if (0 < self::model()->count(
    'centerId = :centerId AND qTypeId = :qTypeId',
    [
        ':centerId' => $centerId,
        ':qTypeId'  => $qTypeId,
    ]
)) {
    throw new Exception('Duplicate Entry for center and que type');
}

相关问题