TimestampBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['created_at','updated_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'], ], ], ]; } public function rules() { return [ [['mall_id','address','address_detail','address_id'], 'required'], [['mall_id', 'created_at', 'updated_at', 'is_delete'], 'integer'], [['name'], 'string', 'max' => 65], [['address', 'address_detail', 'mobile', 'remark'], 'string', 'max' => 255], ]; } public function beforeValidate() { $arr = DistrictArr::getArr(); $area = $arr[$this->address_id]; $city = $arr[$area['parent_id']]; $province = $arr[$city['parent_id']]; $this->address = json_encode([[$province['id'],$province['name']],[$city['id'],$city['name']],[$area['id'],$area['name']]]); return parent::beforeValidate(); // TODO: Change the autogenerated stub } public function afterFind() { parent::afterFind(); // TODO: Change the autogenerated stub if($this->address){ $address = json_decode($this->address); $this->full_address = $address[0][1].$address[1][1].$address[2][1].$this->address_detail; $this->address_id =$address[2][0]; } } }