예제 #1
0
    /**
     * 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;
    }
예제 #2
0
 /**
  * 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;
 }
예제 #3
0
/* @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>
예제 #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getLocations()
 {
     return $this->hasMany(Locations::className(), ['user_id' => 'id']);
 }
예제 #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getLoc()
 {
     return $this->hasOne(Locations::className(), ['id' => 'loc_id']);
 }
예제 #6
0
 /**
  * Finds the Locations model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Locations the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Locations::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #7
0
파일: view.php 프로젝트: sydorenkovd/yiiadv
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']);
?>