获取未知属性:yii \ db \ ActiveQuery :: reg_no

时间:2017-06-08 07:17:10

标签: yii2

我需要帮助,我有一个模型

/**
 * This is the model class for table "student_attachment_details".
 *
 * @property integer $createdBy
 * @property string $reg_no
 * @property string $county_attached
 * @property string $closest_town
 * @property string $company_attached
 * @property integer $company_phone_number
 * @property string $is_assessed
 * @property string $location_description
 * @property integer $department_id
 * @property string $allocated_staff_id
 */

 class StudentAttachmentDetails extends \yii\db\ActiveRecord
 {

但是当我尝试像这样查询模型时

$student_details = StudentAttachmentDetails::find()
                                ->where(['allocated_staff_id'=>'no'])
                                ->limit(1);

然后尝试使用此

获取值
 $reg_no = $student_details->reg_no;

我收到此错误

Getting unknown property: yii\db\ActiveQuery::reg_no

我做错了什么?

1 个答案:

答案 0 :(得分:1)

方法ActiveRecord::find()返回ActiveQuery;要访问实际模型(在类StudentAttachmentDetails的情况下),您需要调用一个方法来执行ActiveQuery

类似

$student_details = StudentAttachmentDetails::find()
                            ->where(['allocated_staff_id'=>'no'])
                            ->limit(1)->one();

会为您提供所需的记录。可以找到ActiveRecord::find()的文档hereActiveQuery::one() here