Exemplo n.º 1
0
 public function actionAjaxGetCountry($search = null, $id = null)
 {
     $out = ['more' => false];
     if (!is_null($search)) {
         $query = Yii::$app->db;
         $data = $query->createCommand('SELECT id, title as text from country where title like "%' . $search . '%" limit 20 ')->queryAll();
         $out['results'] = array_values($data);
     } elseif ($id > 0) {
         $out['results'] = ['id' => $id, 'text' => Country::findOne(['id' => $id])->title];
     } else {
         $out['results'] = ['id' => 0, 'text' => Module::t('geography', 'NO_MATCHING_RECORDS_FOUND')];
     }
     echo Json::encode($out);
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     return ['id' => Module::t('geography', 'ID'), 'title' => Module::t('geography', 'TITLE'), 'country' => Module::t('geography', 'COUNTRY'), 'country_id' => Module::t('geography', 'COUNTRY'), 'latitude' => Module::t('geography', 'LATITUDE'), 'longitude' => Module::t('geography', 'LONGITUDE'), 'is_published' => Module::t('geography', 'PUBLISHED'), 'identifier' => Module::t('geography', 'IDENTIFIER')];
 }
Exemplo n.º 3
0
<?php

use amstr1k\geography\Module;
/* @var $this yii\web\View */
/* @var $model amstr1k\geography\models\City */
$this->title = Module::t('geography', 'EDIT_CITY');
$this->params['breadcrumbs'][] = ['label' => Module::t('amstr1k/geography', 'CITIES'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="city-create">

  <?php 
echo $this->render('_form', ['model' => $model]);
?>

</div>
Exemplo n.º 4
0
<?php

use yii\helpers\Html;
use yii\grid\GridView;
use amstr1k\geography\Module;
/* @var $this yii\web\View */
/* @var $searchModel amstr1k\geography\models\backend\CitySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Module::t('geography', 'CITIES');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="city-index">

  <p>
    <?php 
echo Html::a(Module::t('geography', 'CREATE_CITY'), ['create'], ['class' => 'btn btn-success']);
?>
  </p>

  <?php 
\yii\widgets\Pjax::begin();
?>
  <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'title', ['attribute' => 'country_id', 'value' => function ($model) {
    return $model->country ? $model->country->title : null;
}], ['options' => ['style' => 'width: 5%'], 'class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]);
?>
  <?php 
\yii\widgets\Pjax::end();
?>
Exemplo n.º 5
0
  <?php 
$url = Url::to(['ajax-get-country']);
$initScript = <<<SCRIPT
    function (element, callback) {
        var id=\$(element).val();
        if (id !== "") {
            \$.ajax("{$url}?id=" + id, {
                dataType: "json"
            }).done(function(data) { callback(data.results);});
        }
    }
SCRIPT;
echo $form->field($model, 'country_id')->widget(Select2::classname(), ['options' => ['placeholder' => Module::t('geography', 'SEARCH_COUNTRY')], 'language' => Yii::$app->language == 'ru-RU' ? 'ru' : 'en', 'pluginOptions' => ['allowClear' => true, 'minimumInputLength' => 3, 'ajax' => ['url' => $url, 'dataType' => 'json', 'data' => new JsExpression('function(term,page) { return {search:term}; }'), 'results' => new JsExpression('function(data,page) { return {results:data.results}; }')], 'initSelection' => new JsExpression($initScript)]])->label(Module::t('geography', 'COUNTRY'));
?>

  <?php 
echo $form->field($model, 'is_published')->label(Module::t('geography', 'IS_PUBLISHED'))->checkbox();
?>

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

  <?php 
ActiveForm::end();
?>

</div>
Exemplo n.º 6
0
 /**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     return ['id' => Module::t('geography', 'ID'), 'title' => Module::t('geography', 'TITLE'), 'is_published' => Module::t('geography', 'PUBLISHED')];
 }
Exemplo n.º 7
0
<?php

use amstr1k\geography\Module;
/* @var $this yii\web\View */
/* @var $model amstr1k\geography\models\Country */
$this->title = Module::t('geography', 'EDIT_COUNTRY');
$this->params['breadcrumbs'][] = ['label' => Module::t('geography', 'COUNTRIES'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="country-create">

  <?php 
echo $this->render('_form', ['model' => $model]);
?>

</div>