add events + more wip classes
This commit is contained in:
31
lib/User/Validator/AjaxRequestModelValidator.php
Normal file
31
lib/User/Validator/AjaxRequestModelValidator.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace Da\User\Validator;
|
||||
|
||||
use Da\User\Contracts\ValidatorInterface;
|
||||
use yii\base\Model;
|
||||
use Yii;
|
||||
use yii\bootstrap\ActiveForm;
|
||||
use yii\web\Response;
|
||||
|
||||
class AjaxRequestModelValidator implements ValidatorInterface
|
||||
{
|
||||
protected $model;
|
||||
|
||||
public function __construct(Model $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function validate()
|
||||
{
|
||||
$request = Yii::$app->request;
|
||||
|
||||
if($request->getIsAjax() && !$request->getIsPjax()) {
|
||||
if($this->model->load($request->post())) {
|
||||
Yii::$app->response->format = Response::FORMAT_JSON;
|
||||
echo json_encode(ActiveForm::validate($this->model));
|
||||
Yii::$app->end();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user