Yii Framework Forum: Extending The Cwebuser - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Extending The Cwebuser CException;Property "CWebUser.user_rank" is not defined Rate Topic: -----

#1 User is offline   lefootballroi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 24-September 12

Posted 10 January 2013 - 03:50 AM

Bonjour,

Thanks to everyone for making my experience with Yii an enjoyable one.

Now check this out.

I was successfully able to add information to Yii::app()->user using this page.

http://www.yiiframew...nding-cwebuser/

Now I have implemented mine in this manner

<?php

/**
 * UserIdentity represents the data needed to identity a user.
 * It contains the authentication method that checks if the provided
 * data can identity the user.
 */
class UserIdentity extends CUserIdentity
{
    private $_id;
 
    public function authenticate()
    {
        $username=strtolower($this->username);
        $user=User::model()->find('LOWER(username)=?',array($username));
        if($user===null)
            $this->errorCode=self::ERROR_USERNAME_INVALID;
        else if(!$user->validatePassword($this->password))
            $this->errorCode=self::ERROR_PASSWORD_INVALID;
        else
        {
            $this->_id=$user->id;
            $this->username=$user->username;
			$this->setState("user_rank",$user->user_rank);
            $this->errorCode=self::ERROR_NONE;
        }
        return $this->errorCode==self::ERROR_NONE;
    }
 
    public function getId()
    {
        return $this->_id;
    }
}

Unfortunately I get the error

" CException;Property "CWebUser.user_rank" is not defined" when the session /state is lost

How do I go around this problem to maybe at worst send the user to the login page or at best continue to save the state

Merci beaucoup
0

#2 User is offline   kokomo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 289
  • Joined: 23-July 10

Posted 10 January 2013 - 04:03 AM

Sry I didn't understand your problem.

Can you provide the error stack and more code related to the error.
0

#3 User is offline   lefootballroi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 24-September 12

Posted 10 January 2013 - 05:20 AM

@kokomo

Thanks for the quick response,

I get this error (or can replicate it anyway)

Property "CWebUser.user_rank" is not defined


whenever I open 2 / more tabs of my web app and then log out from one of those tabs and then tries to continue browsing normally in the other tab.

Logically I should have lost the Yii::app()->user->user_rank, which is true.

But with the error being displayed in that manner,i would wish to force the user to the login page when it has been released that the state no more exists


And for the error stack, this below is from
C:\wamp\www\framework\web\auth\CWebUser.php(141)
 /**
131      * PHP magic method.
132      * This method is overriden so that persistent states can be accessed like properties.
133      * @param string $name property name
134      * @return mixed property value
135      */
136     public function __get($name)
137     {
138         if($this->hasState($name))
139             return $this->getState($name);
140         else
141             return parent::__get($name);
142     }


Merci again for your time!
0

#4 User is offline   kokomo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 289
  • Joined: 23-July 10

Posted 14 January 2013 - 09:42 AM

I'm still confused Posted Image about your error description but in general you have to check if user_rank exist at the correct place to avoid this error.

if (!isset($your_var->user_rank)) {
  $this->redirect(Yii::app()->createUrl("user/login"));
}

Can you please provide the full error stack (not only the implementation of the core __get() method) and the relevant code where the error stack hits your custom code.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users