Hye there i have a problem i've design my website using yii framework and now when user register i want to show something like registration successful and redirect to log in page. Unfortunately it keep redirect to log in page without showing any message. Below is my code for user controller
public function actionCreate()
{
$model=new User;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['User']))
{
$model->attributes=$_POST['User'];
if($model->save()) {
$this->redirect(array('profile'));
Yii::app()->user->setFlash('success', 'Registration successful. Please login');
}
}
$this->render('create',array(
'model'=>$model,
));
}
This is the code for my log in
public function actionProfile()
{
$model=$this->loadModel(Yii::app()->user->id);
unset($model->password);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['User']))
{
$model->attributes=$_POST['User'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('update',array(
'model'=>$model,
));
}
This is the code for my access ruler
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('register','create'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('profile', 'history', 'recommendation','view'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete','update','create','index'),
'expression' => 'Yii::app()->user->isAdmin()'
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
This is in my actionview
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
I have just found out my mistake:
instead of this:
I should do like this:
It happened the same, and it turned out that was not going to the "if" because it is not being fulfilled and why not show the message or redirected to another view.
In short, it could perhaps be because you are not fulfilling the condition. ;)
untested but:
should be
You also need to check for the flash message in your view to display it }
Use
return
because it stopped process.