/** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = User::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
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); }