Use Logged In Users Id In Controller Method

Okay, so I am two weeks into learning Yii. I have an Administrator/Manager portal all working well with in a matter of those two weeks. What I am trying to do now is create a small User portal where a user can login and change a couple of their settings, which will later expand. The application is a a web-based administration tool to manage a Postfix+Dovecot email environment, much like PostfixAdmin, which I dislike and has not been updated in a long time.

So, scenario: Administrators login to the Administration portal using credentials from the "users" table in the database while normal Users will login using their email address and password from the "account" table in the database. I am simply providing an interface to allow the user to change their password and a couple more fields. Now, I have the user authentication setup and working fine with the email address and password from the "account" table. What I cannot figure out now is how to get the "actionProfile()" method that is part of the AccountController to use the ID return from Yii::app()->user->getId(). Here is what I have:

	public function actionProfile()















I don’t want to pass any variables through the URL and ideally, I would like every method within the ActionController to be executed using the “account_id” in the “WHERE” clause, if you will. In other words, the next method “actionPassword()” to change the users password by first confirming the current password will need to be executed using the “account_id” as well.

Any help is definitely appreciated.

Thank you in advance!

You need to override the getId() function in your UserIdentity.

This refers to the login-name as default.

Solid, I have already done that. All of that works without a problem.



 * UserIdentity represents the data needed to identify a user.

 * It contains the authentication method that checks if the provided

 * data can identify the user.


class UserIdentity extends CUserIdentity


	private $_id = NULL;


	 * Authenticates a user.

 	* @return boolean whether authentication succeeds.


	public function authenticate()


    	$account = Account::model()->findByAttributes(array('email'=>$this->username));

    	if(!isset($account)) {

        	$this->errorCode = self::ERROR_USERNAME_INVALID;

    	} elseif($account->password !== md5($this->password)) {

        	$this->errorCode = self::ERROR_PASSWORD_INVALID;

    	} else {

	    	$this->_id = $account->account_id;

	    	$this->errorCode = self::ERROR_NONE;


    	return !$this->errorCode;


	public function getId() {

		return $this->_id;



My UserIdentity works just fine. I am trying to get the ID returned from the getId() method to be used as the ID that all Account Models use when getting or setting data.


But usually a loadModel() function takes one parameter, the id. Not an array, try:


If that does not work, please post your loadModel() function aswell.