public function actionLists($id) { $affiliates = Affiliates::find()->where(['company_id' => $id])->all(); if (isset($affiliates) && count($affiliates) > 0) { foreach ($affiliates as $affiliate) { echo "<option value='", $affiliate->id . "'>" . $affiliate->name . "</option>"; } } else { echo "<option> - </option>"; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Affiliates::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; } /** * for searching by name from another table */ $query->joinWith('company'); $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'affiliates.name', $this->name])->andFilterWhere(['like', 'place', $this->place])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'companies.name', $this->company_id]); return $dataProvider; }
echo $form->field($model, 'title')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'description')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'company_id')->dropDownList(ArrayHelper::map(Companies::find()->asArray()->all(), 'id', 'name'), ['prompt' => 'Select Company', 'onchange' => ' $.post("http://orderprocessing/web/admin/affiliates/lists?id=' . '"+$(this).val(), function(data){ $("select#orders-affiliate_id").html(data); });']); ?> <?php echo $form->field($model, 'affiliate_id')->dropDownList(ArrayHelper::map(Affiliates::find()->asArray()->all(), 'id', 'name'), ['prompt' => 'Select Affiliate']); ?> <?php echo $form->field($model, 'order_status_id')->dropDownList(ArrayHelper::map(Orderstatuses::find()->all(), 'id', 'title'), ['prompt' => 'Select Order Status']); ?> <?php echo $form->field($model, 'assignedto_id')->dropDownList(ArrayHelper::map(Users::find()->where(['user_role_id' => 2])->all(), 'id', 'username'), ['prompt' => 'Select User']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?>