public function actionGetFriendType() { $criteria = new CDbCriteria(); $criteria->condition = "uid=:uid OR uid = 0"; $criteria->params = array(':uid' => Yii::app()->user->id); $models = FriendGroup::model()->findAll($criteria); echo '(' . CJSON::encode($models) . ')'; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the primary key value. Defaults to null, meaning using the 'id' GET variable */ public function loadFriendGroup($id = null) { if ($this->_model === null) { if ($id !== null || isset($_GET['id'])) { $this->_model = FriendGroup::model()->findbyPk($id !== null ? $id : $_GET['id']); } if ($this->_model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } } return $this->_model; }
/** * 获得用户的所有好友分组列表 * @param unknown_type $uid * @return Ambigous <mixed, multitype:, NULL, unknown> //TODO cache */ public function getFriendGroups($uid) { $key = "getFriendGroups_{$uid}"; //Yii::app()->cache->delete($key); $resource = Yii::app()->cache->get($key); if ($resource !== false) { return $resource; } if (empty($uid)) { $uid = Yii::app()->user->id; } //初始化 $criteria = new CDbCriteria(); $criteria->order = 'id'; $criteria->condition = "(uid=0 OR uid=:uid) AND id != 1"; $criteria->params = array(':uid' => $uid); $model = new FriendGroup(); $groups = $model->findAll($criteria); $resource = Yii::app()->cache->set($key, $groups); return $groups; }
public function getUserFriendGroups() { //初始化 $criteria = new CDbCriteria(); $criteria->order = 'id'; $criteria->condition = "uid=0 OR uid=:uid"; $criteria->params = array(':uid' => Yii::app()->user->id); $model = new FriendGroup(); $groups = $model->findAll($criteria); return $groups; }
public function actionAddGroup() { $model = new FriendGroup(); $model->scenario = 'add'; if (isset($_POST['FriendGroup'])) { $model->attributes = $_POST['FriendGroup']; if ($model->save()) { $this->redirect(array('index')); } } $data = array('model' => $model); if (Yii::app()->request->isAjaxRequest) { $this->renderPartial('friendGroup', $data, '', TRUE, TRUE); } else { $this->render('friendGroup', $data); } }