File: /home/aliazzsr/api.crm.vqode.com/components/actions/ValidateAction.php
<?php
namespace app\components\actions;
use app\components\BaseModel;
use yii\rest\Action;
use yii\web\NotFoundHttpException;
/**
* Class ValidateAction
* @package app\components\actions
* @property BaseModel $modelClass
*/
class ValidateAction extends Action
{
/**
* @var string the scenario to be assigned to the model before it is validated and updated.
*/
public $scenario = BaseModel::SCENARIO_STRICT_VALIDATE;
/**
* Validates model attributes passed.
*
* @param integer $id model identifier
* @return BaseModel
* @throws \yii\base\InvalidConfigException
* @throws NotFoundHttpException
*/
public function run($id = null)
{
/** @var BaseModel $model */
$model = $id ? $this->findModel($id) : new $this->modelClass();
if(!$model) {
throw new NotFoundHttpException();
}
if ($this->checkAccess) {
call_user_func($this->checkAccess, $this->id, $model);
}
$params = \Yii::$app->getRequest()->getBodyParams();
$model->scenario = $this->scenario;
$model->load($params, '');
$model->validate(array_keys($params));
return $model;
}
}