/** * Lists all CustomerAddress models. * @return mixed */ public function actionIndex() { $searchModel = new CustomerAddressSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $customerModel = ''; if (isset(Yii::$app->request->queryParams['CustomerAddressSearch']['customer_id'])) { $customerModel = Customer::findOne(Yii::$app->request->queryParams['CustomerAddressSearch']['customer_id']); } return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'customerModel' => $customerModel]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function searchForAjax($params) { $query = Customer::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $limit = isset($params['limit']) ? $params['limit'] : 10; $this->username = isset($params['q']) ? $params['q'] : ''; if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['like', 'username', $this->username]); $query->limit($limit); return $dataProvider; }
/** * Finds the Customer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Customer the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Customer::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 表关联 */ public function getCustomer() { return $this->hasOne(Customer::className(), ['id' => 'customer_id']); }