/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tag::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'commend' => $this->commend]); $query->andFilterWhere(['like', 'first', $this->first])->andFilterWhere(['like', 'second', $this->second]); return $dataProvider; }
/** * Finds the Tag model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tag the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tag::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionTag8() { $model = new Tag(); $tag = $model->find()->select('second')->from('tag')->where('second > \'\' and commend=1')->all(); $ans = array(); for ($i = 0; $i < count($tag); $i++) { $ans[$i] = $tag[$i]['second']; // $aa = (new \yii\db\Query ())->select ( 'a.*' )->from ( 'app a' ) // ->join ( 'INNER JOIN', 'appofkind ak', 'a.id=ak.appid and ak.kind=:id',['id'=>$tag[$i]['second']] ) // ->orderBy('a.downloadcount desc') // ->limit(3) // ->all (); // $ans[$tag[$i]['second']]=$aa; } return $ans; }
public function actionTagCommend() { $model = new Tag(); $Tag1s = $model->findBySql("select distinct first from tag where commend=1 and second='' limit 2")->all(); $ans = array(); foreach ($Tag1s as $Tag1) { $model2 = new Tag(); $Tag2s = $model2->find()->select('second')->from('tag')->where('second>\'\' and first=:id', ['id' => $Tag1->first])->all(); $ans[$Tag1->first] = array(); for ($i = 0; $i < count($Tag2s); $i++) { $ans[$Tag1->first][$i] = $Tag2s[$i]['second']; } } return $ans; }