public function actionIndex2() { $session = Yii::$app->session; $language = empty($session['language']) ? 0 : 1; //寻找品牌库 $brandModel = new MirBrand(); $lists = $brandModel->find()->all(); // p($lists); for ($i = 0; $i < count($lists); $i++) { if (!$language) { $data[$i]['name'] = $lists[$i]->brand_name; } else { $data[$i]['name'] = $lists[$i]->brand_name_e; } $data[$i]['pinyi'] = strtoupper(substr(trim($lists[$i]->brand_name_e), 0, 1)); } $data = $this->array_sort($data, 'pinyi', "asc"); for ($i = 0; $i < count($data); $i++) { $newData[$data[$i]['pinyi']][] = $data[$i]['name']; } // p($newData); return $this->render('index2', ['newData' => $newData]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = MirBrand::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(['brand_id' => $this->brand_id]); $query->andFilterWhere(['like', 'brand_name', $this->brand_name])->andFilterWhere(['like', 'brand_name_e', $this->brand_name_e]); return $dataProvider; }
/** * Finds the MirBrand model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MirBrand the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MirBrand::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }