/** * client validation for unique zip_code * @param \yii\base\Model $model * @param string $attribute * @param \yii\web\View $view * @return string */ public function clientValidateAttribute($model, $attribute, $view) { $statuses = json_encode(Locations::find()->select('zip_code')->asArray()->column()); $message = json_encode($this->message, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); return <<<JS if (\$.inArray(value, {$statuses}) > -1) { messages.push({$message}); } JS; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Locations::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->orFilterWhere(['id' => $this->global]); $query->orFilterWhere(['like', 'zip_code', $this->global])->orFilterWhere(['like', 'city', $this->global])->orFilterWhere(['like', 'province', $this->global]); return $dataProvider; }
/* @var $model common\models\Customers */ /* @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')->dropDownList(ArrayHelper::map(Locations::find()->all(), 'id', 'zip_code'), ['prompt' => Yii::t('app', 'Select a Zip Code'), 'id' => 'zipCode']); ?> <?php echo $form->field($model, 'city')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'provice')->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>
echo Html::a('Delete', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]); ?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'zip_code', ['label' => 'Town', 'value' => $model->city], 'province']]); ?> </div> <?php //$format = Yii::$app->formatter; //echo $format->asDate('now', 'php:Y-m-d'); //echo $format->asEmail('*****@*****.**'); // // $q = \common\models\Locations::find()->where(['>=', 'id', '1']); $provider = new \yii\data\ActiveDataProvider(['query' => $q, 'pagination' => ['pageSize' => 4], 'sort' => ['defaultOrder' => ['city' => SORT_DESC]]]); echo \yii\widgets\ListView::widget(['dataProvider' => $provider, 'itemView' => '_instance']); ?>