简体   繁体   English

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

[英]Property “CDbCriteria.:centerId” is not defined in yii

I am using select method in yii it gives error "Property "CDbCriteria.:centerId" is not defined"我在 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');
}

You're using this method in a wrong way.您以错误的方式使用此方法。 You skipped first argument, which should be list of active record arguments used as filter ( see documentation ).您跳过了第一个参数,它应该是用作过滤器的活动记录 arguments 的列表( 请参阅文档)。 You probably need something like:你可能需要类似的东西:

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

Or use count() :或使用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');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM