/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Classify::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['ID' => $this->ID, 'ModuleID' => $this->ModuleID, 'RootID' => $this->RootID, 'Depth' => $this->Depth, 'Orders' => $this->Orders, 'ParentID' => $this->ParentID, 'Child' => $this->Child, 'ShowCount' => $this->ShowCount]); $query->andFilterWhere(['like', 'ClassName', $this->ClassName])->andFilterWhere(['like', 'ClassName_e', $this->ClassName_e])->andFilterWhere(['like', 'Readme', $this->Readme])->andFilterWhere(['like', 'ParentStr', $this->ParentStr])->andFilterWhere(['like', 'ChildStr', $this->ChildStr]); return $dataProvider; }
public function actionIndex() { $classifyModel = new Classify(); $dafenlei = $classifyModel->find()->where(["ParentID" => '0'])->limit(8)->all(); // p($dafenlei); $articleModel = new MirArticle(); $jobs = $articleModel->articleToIndex(5); //技术分享 $jishus = $articleModel->articleToIndex(3); $productModel = new MirProduct(); //ivd 五个广告图 $adModel = new MirAd(); $ads = $adModel->find()->orderBy("ad_rank desc,id desc")->limit(5)->all(); // p($ads); // p($fourPic); // P($ivdList); // p(count($ivdList)); //产品照片显示 $mainClass = $productModel->mainClass(); foreach ($mainClass as $k => $v) { $mainClassId[] = $k; } for ($i = 0; $i < count($mainClassId) - 1; $i++) { $products[] = MirProduct::find()->where(['product_mainclass' => $mainClassId[$i]])->orderBy("product_rank desc,product_id desc")->limit(9)->all(); $data = $productModel->find()->where(["product_mainclass" => $mainClassId[$i]]); $pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '10']); $dataShow = $data->offset($pages->offset)->limit($pages->limit)->orderBy("product_rank desc,product_id desc")->all(); $pagesArray[] = $pages; $productArray[] = $dataShow; } // p(count($products[1])); // p($pagesArray); // p($productArray); $mainClass = array_values($mainClass); return $this->render('index', ['dafenlei' => $dafenlei, 'jobs' => $jobs, 'jishus' => $jishus, 'ivdList' => $ivdList, 'mainClass' => $mainClass, 'products' => $products, 'productArray' => $productArray, 'pagesArray' => $pagesArray, 'ads' => $ads]); }