mongosoft\file\UploadBehavior::beforeValidate PHP Метод

beforeValidate() публичный Метод

This method is invoked before validation starts.
public beforeValidate ( )
    public function beforeValidate()
    {
        /** @var BaseActiveRecord $model */
        $model = $this->owner;
        if (in_array($model->scenario, $this->scenarios)) {
            if (($file = $model->getAttribute($this->attribute)) instanceof UploadedFile) {
                $this->_file = $file;
            } else {
                if ($this->instanceByName === true) {
                    $this->_file = UploadedFile::getInstanceByName($this->attribute);
                } else {
                    $this->_file = UploadedFile::getInstance($model, $this->attribute);
                }
            }
            if ($this->_file instanceof UploadedFile) {
                $this->_file->name = $this->getFileName($this->_file);
                $model->setAttribute($this->attribute, $this->_file);
            }
        }
    }

Usage Example

 /**
  * @inheritdoc
  */
 public function beforeValidate()
 {
     /** @var BaseActiveRecord $model */
     $model = $this->owner;
     if (empty($this->crop_field)) {
         $this->crop_value = $model->getAttribute($this->attribute);
         $this->crop_changed = !empty($this->crop_value);
     } else {
         $this->crop_value = $model->getAttribute($this->crop_field);
         $this->crop_changed = $model->isAttributeChanged($this->crop_field);
     }
     parent::beforeValidate();
 }
All Usage Examples Of mongosoft\file\UploadBehavior::beforeValidate