I create the yii application for my final project. But i found the error result in the returning the IDROLE from my database. In the user identity page, i returning this into the $_idrole variable.
Quote
class UserIdentity extends CUserIdentity
{
…
public $_idrole;
public function authenticate()
{
.....
$this->_id=$user->IDUSER;
$this->_idrole=$user->IDROLE;
$this->username=$user->USERNAME;
.....</div></div>
Then in the Login form i returning again like this:
The assignment $this->id_role=$form->idrole; should occur AFTER you call validate() method of the form because $form->idrole is populated in authenticate method which is called by validate().
redirect() will terminate current request and redirect to another page. Code after this line will not be executed. Even if it is executed, $this->id_role won't be available in the next request. You need to store it in session.
I'm being frustated with this project. I'm purely newbie in the php programmming. So i didn't know how to fix this. please help me to fix this project. i don'd know what should i do… thanks…
You may try the following code. After redirection, if you want to access the role ID, you can use $this->roleID (because we have getter 'getRoleID' defined):
<?php
public function actionXyz()
{
......
$form->attributes=$_POST['FormClass'];
if($form->validate())
{
$_SESSION['RoleID']=$form->idrole;
$this->redirect(...);
}
}
public function getRoleID()
{
return isset($_SESSION['RoleID']) ? $_SESSION['RoleID'] : null;
}