public function actionAdd() { $user = User::model()->findByPk(Yii::app()->request->getParam('id')); if ($user === null || $user->id === Yii::app()->getUser()->getId()) { throw new CHttpException(404, Yii::t('application', 'The user you are trying to add as a contact is not available.')); } if (User::areContacts(Yii::app()->getUser()->getId(), $user->id)) { throw new CException(401, Yii::t('application', 'You and {username} are already contacts.', array('{username}' => $user->username))); } $request = new Request(); $request->user_id = Yii::app()->user->getId(); $request->contact_id = $user->id; if ($request->save()) { $this->redirect($user->getUrl()); } else { throw new CException(Yii::t('application', 'Write error message here')); } }