There is an Item controller, an actionCreate and a handler in it.
public function actionCreate() { $item = new Item(); $file = new File(); $file->trigger(File::FILE_UPLOADS); if ( Yii::$app->request->isAjax && $item->load( Yii::$app->request->post() ) ) { $item->attributes = Yii::$app->request->post('Item'); $errors = ActiveForm::validate( $item ); } if( $errors ) { Yii::$app->response->format = Response::FORMAT_JSON; return $errors; } } And the File model
class File extends \yii\db\ActiveRecord { const FILE_UPLOADS = 'file-uploads'; public function init() { $this->on(self::FILE_UPLOADS, [$this, 'uploads']); } public function uploads( $event ) { $file = new File(); if ( Yii::$app->request->isAjax && $file->load( Yii::$app->request->post() ) ) { $file->image = UploadedFile::getInstance($file, "image"); } $errors = ActiveForm::validate( $file ); return $errors; } } The file is submitted for validation, everything seems to be ok, but I don’t understand how I can return the result back to the Item controller, i.e. is this part?
$errors = ActiveForm::validate( $file ); Ideally, I want to completely separate Item and File, but for now I don’t understand how, please tell me.