Yii Framework Forum: Getting The Right Object Name In Ewebuser - Yii Framework Forum

Jump to content

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

Getting The Right Object Name In Ewebuser

#1 User is offline   mbaksri 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 15-July 11

Posted 11 January 2013 - 02:51 AM

Hi, everyone. I want to ask about an error in login action. Let say that i have an application. Those are my code..
EWebUser.php
<?php
class EWebUser extends CWebUser{

    protected $_model;
 
   protected function loadUser()
    {
        if ( $this->_model === null ) {
                $this->_model = StaffDb::model()->findByPk($this->id);
        }
        return $this->_model;
    }

    function getLevel()
    {
        $user=$this->loadUser();
        if ($user->kdstpeg == 02){
        if(substr($user->kdorg,1,4) == '0000') $level=1;
        else if (substr($user->kdorg,2,3) == '000') $level=2;

            return $level;
        }
        return 100;
    }


UserIdentity.php
<?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 = MUser::model()->find('LOWER(username)=?', array($username));
                if($user===null)
			$this->errorCode=self::ERROR_USERNAME_INVALID;
			else if ($user->pwd!=$this->password)
			$this->errorCode = self::ERROR_PASSWORD_INVALID;
                else
                {
					$this->_id = $user->oldStaffCode;
					$this->username = $user->username;
					$this->errorCode = self::ERROR_NONE;
                }
        return $this->errorCode == self::ERROR_NONE;
	}

	 public function getId()
	{
		return $this->_id;
        }
}

and StaffDb.php (one of my model)
public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'staffdb';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('oldStaffCode', 'required'),
			... array('kdstpeg', 'max'=>2),
			
			array('...', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('oldStaffCode, kdstpeg, ..., 'safe', 'on'=>'search'),
		);
	}


        public function primaryKey()
        {
          return 'oldStaffCode';
        }


When i'm trying to access this application, the error "Trying to get property of non-object" is shown. Then, i put this code on EWebUser.php
print_r ($user);
in order to see what kind of $user's view. But it didn't have any effect. :(
My question is, did I miss something in that codes? Because in my opinion, all of objects are complete. I hope there's a suggestion to solve this problem. Thanks in advance. :D
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