/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new UserFriend(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST)) { $model->friendId = $_POST['friendId']; $model->userId = Yii::app()->user->id; if ($model->save()) { $arr = array('r' => 1, 'action' => 'cancel'); } else { $arr = array('r' => 0); } } else { $arr = array('r' => -1, 'msg' => '非法操作'); } echo json_encode($arr); // $this->render('create',array( // 'model'=>$model, // )); }
public function actionaddFriend($userId) { $friends = new UserFriend(); $friends->user_id = Yii::app()->user->userId; $friends->friend_id = $userId; $friends->status = 0; $friends->save(); $name = UserProfile::model()->find('user_id=:uid', array(':uid' => Yii::app()->user->userId)); $link = Yii::app()->baseUrl . "/index.php/user/confirmfriend/userId/" . Yii::app()->user->userId . "/senderId/" . $userId; $link1 = Yii::app()->baseUrl . "/index.php/user/viewprofile/userId/" . Yii::app()->user->userId; $message = $name['first_name'] . " " . $name['last_name'] . " want to become a friend " . "<span><a href ='{$link1}'>View user</a></span>  <span><a href ='{$link}'>Accept</a></span>"; $date = date('Y-m-d H:i:s'); $this->notification(Yii::app()->user->userId, $userId, $message, $date, 'friend'); }