/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $id = Yii::$app->user->id; $query = EntpCustomer::find(); $query->joinWith(['customer'])->where('entp_customer.entrepreneur_user_id=' . $id); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['name'] = ['asc' => ['customer.name' => SORT_ASC], 'desc' => ['customer.name' => SORT_DESC]]; $dataProvider->sort->attributes['pic'] = ['asc' => ['customer.pic' => SORT_ASC], 'desc' => ['customer.pic' => SORT_DESC]]; $dataProvider->sort->attributes['telephone'] = ['asc' => ['customer.telephone' => SORT_ASC], 'desc' => ['customer.telephone' => SORT_DESC]]; $dataProvider->sort->attributes['mobile'] = ['asc' => ['customer.mobile' => SORT_ASC], 'desc' => ['customer.mobile' => SORT_DESC]]; $dataProvider->sort->attributes['email'] = ['asc' => ['customer.email' => SORT_ASC], 'desc' => ['customer.email' => SORT_DESC]]; $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(['entrepreneur_user_id' => $this->entrepreneur_user_id, 'customer_id' => $this->customer_id]); $query->andFilterWhere(['like', 'customer.name', $this->name])->andFilterWhere(['like', 'customer.pic', $this->pic])->andFilterWhere(['like', 'customer.telephone', $this->telephone])->andFilterWhere(['like', 'customer.mobile', $this->mobile])->andFilterWhere(['like', 'customer.email', $this->email]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getEntpCustomers() { return $this->hasMany(EntpCustomer::className(), ['entrepreneur_user_id' => 'user_id']); }
$id = Yii::$app->user->id; ?> <div class="entp-invoice-form"> <?php $form = ActiveForm::begin(); ?> <div class="row"> <div class="col-lg-5"> <?php echo $form->field($model, 'customerSelect')->label('Select Customer')->dropDownList(ArrayHelper::map(EntpCustomer::find()->joinWith('customer')->where('entp_customer.entrepreneur_user_id=' . $id)->all(), 'customer.id', 'customer.name'), ['style' => 'width:230px;', 'tabindex' => '3', 'prompt' => '', 'id' => 'customerSelect']); ?> <div id="hehe"> </div> <?php echo $form->field($model, 'customer')->textInput(['maxlength' => true, 'id' => 'customer'])->label('Name'); ?> <?php echo $form->field($model, 'address')->textInput(['maxlength' => true, 'id' => 'address']); ?> <?php
/** * @return \yii\db\ActiveQuery */ public function getEntpCustomers() { return $this->hasMany(EntpCustomer::className(), ['customer_id' => 'id']); }
/** * Finds the EntpCustomer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $entrepreneur_user_id * @param integer $customer_id * @return EntpCustomer the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($entrepreneur_user_id, $customer_id) { if (($model = EntpCustomer::findOne(['entrepreneur_user_id' => $entrepreneur_user_id, 'customer_id' => $customer_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }