255], [['access_code'], 'string', 'max' => 4], [['sharer_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['sharer_id' => 'id']], [['access_code'], 'required', 'on' => self::SCENARIO_UPDATE], // 在 'update' 场景中,只验证 'access_code' 字段 ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'share_id' => '分享ID', 'sharer_id' => '分享者ID', 'file_relative_path' => '文件位置', 'access_code' => '访问密码', 'creation_date' => '分享创建日期', ]; } /** * Gets query for [[Sharer]]. * * @return ActiveQuery */ public function getSharer() { return $this->hasOne(User::class, ['id' => 'sharer_id']); } public function getSharerUsername() { return $this->sharer->username; } }