Am I forced to use CDbCommand in this case?

Hi, I have the following code:

$users = Users::model()->find('LOWER(EMAIL)=?',array(strtolower($this->EMAIL)));


		if($users === null)


		else if(($this->PASSWORD)!==$users->PASSWORD)








			$this->setState("USER_ID", $this->_ID);

			$this->setState("EMAIL", $this->EMAIL);

			$this->setState("IS_VIP", 0 or 1 - > this should be a variable with the result from the comparision);



		return !$this->errorCode;

$users->VIP_UNTIL should be a field from the database. The problem is how to compare NOW() and VIP_UNTIL. I can't use the IF/SWITCH approach as I am extracting data. Moreover, I am extracting data, so I suppose, I can't use the CDbExp​ression. Actually, the task is to understand whether VIP_UNTIL > NOW() and set the VIP state property to 1. Otherwise, to assign 0 to it.

You can still use AR. You can pass a CDbCriteria instance to find(). You need to specify the 'select' property of CDbCriteria so that you can extract the needed VIP attribute using your exp​ression.

Qiang, I understood that this might not be a solution. The problem is not in your idea, but in the fact that if I record the thing in a session, the user can stay "forever" and thus, he remains VIP until he gets logged out. The possible implementation is to perform VIP checks on sensitive places, it couldn't be dine by a custom function which checks whether the current user is VIP or not. This is actually for rules, I would be happy if this is implemented in accessControl too(I mean custom function or something)…

If you need to check VIP in real time, you need to extend CWebUser to do it because UserIdentity is only used when performing authentication.