/** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'view' page. * @title: Создание * @return mixed */ public function actionCreate() { $model = new User(); $model->setScenario(User::CREATE_SCENARIO); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function testUpdateExistingUploadCollection() { $user = new User(); $user->username = '******'; $user->email = '*****@*****.**'; $user->password = '******'; $user->image_path = [$this->pathToImage, $this->pathToImage]; $user->attachBehavior('multipleUpload', ['class' => behaviors\UploadBehaviour::className(), 'multiple' => true, 'fields' => ['image_path']]); $user->save(); $user->trigger(yii\db\ActiveRecord::EVENT_AFTER_FIND); $collectionId = $user->image_path->id; $compareUser = User::findOne($user->id); $compareUser->image_path = [$this->pathToImage]; $compareUser->attachBehavior('multipleUpload', ['class' => behaviors\UploadBehaviour::className(), 'multiple' => true, 'fields' => ['image_path']]); $compareUser->save(); $compareUser->trigger(yii\db\ActiveRecord::EVENT_AFTER_FIND); $compareUserCollectionId = $compareUser->image_path->id; $files = $user->image_path->getUploads(); $this->assertCount(3, $files); $this->assertEquals($collectionId, $compareUserCollectionId); }