示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Location::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;
     }
     $query->andFilterWhere(['location_id' => $this->location_id]);
     $query->andFilterWhere(['like', 'zip_code', $this->zip_code])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'province', $this->province]);
     return $dataProvider;
 }
 /**
  * Finds the Location model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Location the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Location::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#3
0
/* @var $form yii\widgets\ActiveForm */
?>

<div class="customers-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'customer_name')->textInput(['maxlength' => true]);
?>

    
    <?php 
echo $form->field($model, 'zip_code')->widget(Select2::classname(), ['data' => ArrayHelper::map(Location::find()->all(), 'location_id', 'zip_code'), 'language' => 'en', 'options' => ['placeholder' => 'Select a zipcode...', 'id' => 'zip_code'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
echo $form->field($model, 'city')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'province')->textInput(['maxlength' => true]);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>