public function beforeValidate() { if (!$this->ip) { $this->ip = Yii::app()->getRequest()->userHostAddress; } return parent::beforeValidate(); }