/** * Finds user by [[username]] * * @return User|null */ protected function getUser() { if ($this->_user === null) { $this->_user = User::findByEmail($this->email); } return $this->_user; }
$form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'username')->textInput(); ?> <?php echo $form->field($model, 'email')->textInput(); ?> <?php if (\yii::$app->getUser()->can("rbac/roles/update")) { echo $form->field($model, 'role')->dropDownList(Role::getAllRolesForDropdown()); } if (\yii::$app->getUser()->can("users/usercontroller/update")) { echo $form->field($model, 'status')->dropDownList(User::getUserStatusList()); } ?> <?php echo $form->field($model, 'password')->passwordInput(); ?> <?php echo $form->field($model, 'image')->widget(Kcfinder::className()); ?> <?php echo $form->field($model, 'file_collection_id[]')->widget(Kcfinder::className(), ['multiple' => true]); ?> <?php
/** * 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.'); } }
/** * @inheritdoc */ public function actions() { return ['error' => ['class' => 'yii\\web\\ErrorAction'], 'gallery' => ['class' => GalleryManagerAction::className(), 'types' => ['user' => User::className()]]]; }
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); }