Example #1
0
 /**
  * Создает DataProvider на основе переданных данных
  * @param $params - параметры
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Country::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $this::COUNT]]);
     $this->load($params);
     // Если валидация не пройдена, то ничего не выводить
     if (!$this->validate()) {
         $query->where('0=1');
         return $dataProvider;
     }
     // Фильтрация
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'currency_code', $this->currency_code])->andFilterWhere(['like', 'currency', $this->currency]);
     return $dataProvider;
 }
Example #2
0
 /**
  * Страна текущего города
  * @return \yii\db\ActiveQuery
  */
 public function getCountry()
 {
     return $this->hasOne(Country::className(), ['id' => 'country_id']);
 }
Example #3
0
use yii\helpers\Html;
use kartik\grid\GridView;
use yii\helpers\Url;
use lowbase\user\UserAsset;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('user', 'Города');
$this->params['breadcrumbs'][] = $this->title;
$assets = UserAsset::register($this);
?>
<div class="city-index">

    <?php 
$gridColumns = [['class' => 'kartik\\grid\\SerialColumn', 'contentOptions' => ['class' => 'kartik-sheet-style'], 'width' => '30px', 'header' => '', 'headerOptions' => ['class' => 'kartik-sheet-style']], ['attribute' => 'id', 'width' => '70px'], ['attribute' => 'country_id', 'value' => function ($model) {
    return $model->country_id && isset($model->country) ? $model->country->name : null;
}, 'filter' => Country::getAll(), 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'width' => '150px', 'filterInputOptions' => ['placeholder' => ' ', 'class' => 'form-control']], 'city', 'state', 'region', ['template' => '{view} {update} {delete}', 'class' => 'kartik\\grid\\ActionColumn'], ['class' => 'kartik\\grid\\CheckboxColumn', 'headerOptions' => ['class' => 'kartik-sheet-style']]];
echo GridView::widget(['layout' => "{items}\n{summary}\n{pager}", 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => $gridColumns, 'containerOptions' => ['style' => 'overflow: auto'], 'headerRowOptions' => ['class' => 'kartik-sheet-style'], 'filterRowOptions' => ['class' => 'kartik-sheet-style'], 'pjax' => false, 'panel' => ['heading' => '<i class="glyphicon glyphicon-stats"></i> ' . Yii::t('user', 'Города'), 'type' => GridView::TYPE_PRIMARY, 'before' => Html::a('<span class="glyphicon glyphicon-plus"></span> ' . Yii::t('user', 'Добавить'), ['city/create'], ['class' => 'btn btn-success']), 'after' => "<div class='text-right'><b>" . Yii::t('user', 'Выбранные') . ":</b> " . Html::button('<span class="glyphicon glyphicon-trash"></span> ' . Yii::t('user', 'Удалить'), ['class' => 'btn btn-danger delete-all']) . "</div>"], 'export' => ['fontAwesome' => true], 'bordered' => true, 'striped' => true, 'condensed' => true, 'persistResize' => false, 'hover' => true, 'responsive' => true]);
?>

</div>

<?php 
$this->registerJs('
        $(".delete-all").click(function(){
        var keys = $(".grid-view").yiiGridView("getSelectedRows");
        $.ajax({
            url: "' . Url::to(['city/multidelete']) . '",
            type:"POST",
            data:{keys: keys},
            success: function(data){
                location.reload();
Example #4
0
            </p>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12">
            <?php 
echo $form->field($model, 'city')->textInput(['maxlength' => true]);
?>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-6">
            <?php 
echo $form->field($model, 'country_id')->widget(Select2::classname(), ['data' => Country::getAll(), 'options' => ['placeholder' => $model->getAttributeLabel('country_id')], 'pluginOptions' => ['allowClear' => true]]);
?>
        </div>
        <div class="col-lg-6">
            <?php 
echo $form->field($model, 'state')->textInput(['maxlength' => true]);
?>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-6">
            <?php 
echo $form->field($model, 'region')->textInput(['maxlength' => true]);
?>
        </div>
Example #5
0
 /**
  * Поиск модели (страны) по ID
  * @param integer $id
  * @return Country the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Country::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('user', 'Запрошенная страница не найдена.'));
     }
 }