public function actionAlbum($id) { $album = DictEnAlbum::findOne($id); // $totalCount = \Yii::$app->db->createCommand('select count(*) from tbl_dict_en2album where albumId='.$id)->queryScalar(); // $pages = new Pagination(['totalCount' => $totalCount]); // $DictEnIds = \Yii::$app->db->createCommand('select wordId from tbl_dict_en2album where albumId='.$id.' limit '.$pages->offset.' , '.$pages->limit)->queryColumn(); // $words = DictEn::find()->where('id in('.implode(',', $DictEnIds).')')->all(); $query = DictEn::find()->join('INNER JOIN', 'tbl_dict_en2album', 'tbl_dict_en2album.albumId=' . $id . ' and tbl_dict_en2album.wordId = tbl_dict_en.id'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $words = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('../album/view', ['model' => $album, 'words' => $words, 'pages' => $pages]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = DictEnAlbum::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, 'create_time' => $this->create_time, 'update_time' => $this->update_time, 'comment_time' => $this->comment_time, 'author_id' => $this->author_id, 'comment_num' => $this->comment_num, 'view_num' => $this->view_num, 'fav_num' => $this->fav_num, 'digg_num' => $this->digg_num, 'share_num' => $this->share_num]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'litPic', $this->litPic])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Finds the DictEnAlbum model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return DictEnAlbum the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = DictEnAlbum::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }