public function actionChangePassword() { $model = new PasswordChangeForm(); if (isset($_POST["PasswordChangeForm"])) { $attributes = $_POST["PasswordChangeForm"]; $currentUserId = Yii::app()->user->id; $model->user_id = $currentUserId; $model->setAttributes($attributes); if ($model->validate()) { $user = User::model()->findByPk($currentUserId); $user->password = $_POST["PasswordChangeForm"]["password"]; $user->password_repeat = $_POST["PasswordChangeForm"]["password"]; Yii::app()->user->setFlash("success", "登入密碼已更改"); if ($user->save()) { $this->redirect("index"); } } } $this->render("changePassword", array("model" => $model)); }
<?php namespace Pages\MonCompte; require __DIR__ . '../../../../core/initialize.php'; class PasswordChangeForm extends \PageHelper { public $isProtected = true; public $strTemplate = "PasswordChangeForm.html5.twig"; public function run() { $view = $this->template->render($this->arrayTemplate); $this->response->setContent($view); $this->response->send(); } } $class = new PasswordChangeForm(); $class->run();