This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace frontend\controllers; | |
| use Yii; | |
| use frontend\models\Profile; | |
| use frontend\models\search\ProfileSearch; | |
| use yii\web\Controller; | |
| use yii\web\NotFoundHttpException; | |
| use yii\filters\VerbFilter; | |
| use common\models\PermissionHelpers; | |
| use common\models\RecordHelpers; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function behaviors() | |
| { | |
| return [ | |
| 'access' => [ | |
| 'class' => \yii\filters\AccessControl::className(), | |
| 'only' => ['index', 'view','create', 'update', 'delete'], | |
| 'rules' => [ | |
| [ | |
| 'actions' => ['index', 'view','create', 'update', 'delete'], | |
| 'allow' => true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function actionIndex() | |
| { | |
| if ($already_exists = RecordHelpers::userHas('profile')) { | |
| return $this->render('view', [ | |
| 'model' => $this->findModel($already_exists), | |
| ]); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function actionView() | |
| { | |
| if ($already_exists = RecordHelpers::userHas('profile')) { | |
| return $this->render('view', [ | |
| 'model' => $this->findModel($already_exists), | |
| ]); | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function actionCreate() | |
| { | |
| $model = new Profile; | |
| $model->user_id = \Yii::$app->user->identity->id; | |
| if ($already_exists = RecordHelpers::userHas('profile')) { | |
| return $this->render('view', [ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function actionUpdate() | |
| { | |
| if($model = Profile::find()->where(['user_id' => Yii::$app->user->identity->id])->one()) { | |
| if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
| return $this->redirect(['view']); | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function actionDelete() | |
| { | |
| $model = Profile::find()->where(['user_id' => Yii::$app->user->identity->id])->one(); | |
| $this->findModel($model->id)->delete(); | |
| return $this->redirect(['site/index']); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use yii\helpers\Html; | |
| use yii\widgets\DetailView; | |
| use common\models\PermissionHelpers; | |
| /** | |
| * @var yii\web\View $this | |
| * @var app\models\Profile $model | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use yii\helpers\Html; | |
| use yii\widgets\ActiveForm; | |
| /** | |
| * @var yii\web\View $this | |
| * @var app\models\Profile $model | |
| * @var yii\widgets\ActiveForm $form | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function beforeValidate() | |
| { | |
| if ($this->birthdate != null) { | |
| $new_date_format = date('Y-m-d', strtotime($this->birthdate)); | |
| $this->birthdate = $new_date_format; | |
| } | |
| return parent::beforeValidate(); | |
| } |