public function actionIndex() { // $this->render('index'); if (!empty($_GET['user'])) { if (is_numeric($_GET['user'])) { $user_id = intval($_GET['user']); $user = new User(); // var_dump($user); $user_info = $user->findByPk($user_id); // $user_info=$user->find('id=:id',array(':id'=>$user_id)); // var_dump($user_info); // $needing_get=NeedingGet::model()->findAll('username=:username',array(':username'=>Yii::app()->user->name)); $needingGetCount = NeedingGet::model()->count('username=:username', array(':username' => Yii::app()->user->name)); $neededGetCount = NeedingGet::model()->count('push_user=:username', array(':username' => Yii::app()->user->name)); $starCount = Yii::app()->db->createCommand("select sum(star) as star_sum from needingGet where username=:username")->query(array(':username' => Yii::app()->user->name))->readAll(); $from_count = empty($_GET['page']) || !is_numeric($_GET['page']) ? 0 : $_GET['page']; $page_size = 10; $needing_get = Yii::app()->db->createCommand("select * from needingget as A left join needing as B on A.needing_id=B.id limit {$from_count},{$page_size}")->queryAll(); if (!empty($_GET['action']) && $_GET['action'] == 'more') { echo json_encode($needing_get); exit; } $this->render('index', array('user' => $user_info, 'needing_get' => $needing_get, 'needingGetCount' => $needingGetCount, 'starSum' => $starCount[0], 'neededGetCount' => $neededGetCount)); exit; } } }
public function actionIndex() { $needing_id = $_GET['id']; //需求不复杂使用ar //需求复杂可用dao(cdbcommand) //查询条件多用cdbcreteria类 $needing = new Needing(); $info = $needing->find('id=:id', array(':id' => $needing_id)); //收藏 $collection = Collection::model()->count('user_id=:user_id and needing_id=:cat_id', array(':user_id' => Yii::app()->user->id, ':cat_id' => $needing_id)); //验证是否已参与需求 $needing_gotAll = NeedingPre::model()->findAll('needing_id=:needing_id', array(':needing_id' => $needing_id)); $needing_gotCheck = NeedingPre::model()->count('needing_id=:needing_id and username=:username', array(':needing_id' => $needing_id, ':username' => Yii::app()->user->name)); //需求是否已托管 $needing_tuoguan = NeedingGet::model()->find('needing_id=:needing_id', array(':needing_id' => $needing_id)); $this->render('index', array('needing' => $info, 'collect_num' => $collection, 'needing_got' => $needing_gotCheck, 'needing_gotAll' => $needing_gotAll, 'needing_tuoguan' => $needing_tuoguan, 'needing_reply' => '')); }