Commit 98e0ece9 by Junaid Rahman pv

modified state and district

parent fb1db90b
...@@ -34,19 +34,20 @@ $config = [ ...@@ -34,19 +34,20 @@ $config = [
], ],
], ],
'modules' => [ 'modules' => [
'business' => [
'class' => 'backend\modules\business\Module',
],
'location' => [
'class' => 'backend\modules\location\Module',
],
'i18n' => [ 'i18n' => [
'class' => 'backend\modules\i18n\Module', 'class' => 'backend\modules\i18n\Module',
'defaultRoute' => 'i18n-message/index' 'defaultRoute' => 'i18n-message/index'
], ],
'theme' => [ 'theme' => [
'class' => 'backend\modules\theme\Module', 'class' => 'backend\modules\theme\Module',
],
'business' => [
'class' => 'backend\modules\business\Module',
],
'location' => [
'class' => 'backend\modules\location\Module',
] ]
], ],
'as globalAccess' => [ 'as globalAccess' => [
'class' => '\common\behaviors\GlobalAccessBehavior', 'class' => '\common\behaviors\GlobalAccessBehavior',
......
...@@ -8,6 +8,8 @@ use backend\modules\location\models\search\DistrictSearch; ...@@ -8,6 +8,8 @@ use backend\modules\location\models\search\DistrictSearch;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\helpers\ArrayHelper;
use common\models\State;
/** /**
* DistrictController implements the CRUD actions for District model. * DistrictController implements the CRUD actions for District model.
...@@ -64,12 +66,14 @@ class DistrictController extends Controller ...@@ -64,12 +66,14 @@ class DistrictController extends Controller
public function actionCreate() public function actionCreate()
{ {
$model = new District(); $model = new District();
$states = ArrayHelper::map(State::find()->all(), 'id', 'name');
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]); return $this->redirect(['view', 'id' => $model->id]);
} else { } else {
return $this->render('create', [ return $this->render('create', [
'model' => $model, 'model' => $model,
'states' => $states,
]); ]);
} }
} }
...@@ -83,12 +87,14 @@ class DistrictController extends Controller ...@@ -83,12 +87,14 @@ class DistrictController extends Controller
public function actionUpdate($id) public function actionUpdate($id)
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
$states = ArrayHelper::map(State::find()->all(), 'id', 'name');
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]); return $this->redirect(['view', 'id' => $model->id]);
} else { } else {
return $this->render('update', [ return $this->render('update', [
'model' => $model, 'model' => $model,
'states' => $states,
]); ]);
} }
} }
...@@ -106,6 +112,7 @@ class DistrictController extends Controller ...@@ -106,6 +112,7 @@ class DistrictController extends Controller
return $this->redirect(['index']); return $this->redirect(['index']);
} }
/** /**
* Finds the District model based on its primary key value. * Finds the District model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown. * If the model is not found, a 404 HTTP exception will be thrown.
......
...@@ -2,42 +2,35 @@ ...@@ -2,42 +2,35 @@
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use common\models\State;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\District */ /* @var $model common\models\District */
/* @var $form yii\widgets\ActiveForm */ /* @var $form yii\widgets\ActiveForm */
/* @var $states array */
?> ?>
<div class="district-form"> <div class="district-form">
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="info">
<div class="page-header">
<h3>Info</h3>
</div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<?= $form->field($model, 'state_id') <?= $form->field($model, 'state_id')->dropDownList($states) ?>
->dropDownList(ArrayHelper::map(State::find()->all(), 'id', 'name')) ?>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<?php echo $form->field($model, 'name')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<?php echo $form->field($model, 'slug')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'slug')->textInput(['maxlength' => true]) ?>
</div> </div>
</div> </div>
...@@ -54,9 +47,6 @@ use common\models\State; ...@@ -54,9 +47,6 @@ use common\models\State;
'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div> </div>
</div>
</div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>
......
<?php <?php
use yii\helpers\Html;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\District */ /* @var $model common\models\District */
/* @var $states array */
$this->title = Yii::t('backend', 'Create District'); $this->title = Yii::t('backend', 'Create District');
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Districts'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Districts'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="district-create">
<div class="district-create">
<?= $this->render('_form', [ <?= $this->render('_form', [
'model' => $model, 'model' => $model,
'states' => $states
]) ?> ]) ?>
</div> </div>
...@@ -39,7 +39,8 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -39,7 +39,8 @@ $this->params['breadcrumbs'][] = $this->title;
// 'created_at', // 'created_at',
// 'updated_at', // 'updated_at',
['class' => 'yii\grid\ActionColumn'], ['class' => 'yii\grid\ActionColumn',
'template' => '{update}{delete}'],
], ],
]); ?> ]); ?>
</div> </div>
...@@ -4,6 +4,7 @@ use yii\helpers\Html; ...@@ -4,6 +4,7 @@ use yii\helpers\Html;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\District */ /* @var $model common\models\District */
/* @var $states array */
$this->title = Yii::t('backend', 'Update {modelClass}: ', [ $this->title = Yii::t('backend', 'Update {modelClass}: ', [
'modelClass' => 'District', 'modelClass' => 'District',
...@@ -18,6 +19,7 @@ $this->params['breadcrumbs'][] = Yii::t('backend', 'Update'); ...@@ -18,6 +19,7 @@ $this->params['breadcrumbs'][] = Yii::t('backend', 'Update');
<?= $this->render('_form', [ <?= $this->render('_form', [
'model' => $model, 'model' => $model,
'states' => $states
]) ?> ]) ?>
</div> </div>
...@@ -40,7 +40,8 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -40,7 +40,8 @@ $this->params['breadcrumbs'][] = $this->title;
//'created_at', //'created_at',
// 'updated_at', // 'updated_at',
['class' => 'yii\grid\ActionColumn'], ['class' => 'yii\grid\ActionColumn',
'template' => '{update}{delete}'],
], ],
]); ?> ]); ?>
......
...@@ -56,6 +56,7 @@ class District extends \yii\db\ActiveRecord ...@@ -56,6 +56,7 @@ class District extends \yii\db\ActiveRecord
{ {
return [ return [
[['state_id', 'name'], 'required'], [['state_id', 'name'], 'required'],
[['name'], 'unique'],
[['state_id', 'status', 'created_at', 'updated_at'], 'integer'], [['state_id', 'status', 'created_at', 'updated_at'], 'integer'],
[['name', 'slug'], 'string', 'max' => 1024], [['name', 'slug'], 'string', 'max' => 1024],
[['state_id'], 'exist', 'skipOnError' => true, 'targetClass' => State::className(), 'targetAttribute' => ['state_id' => 'id']], [['state_id'], 'exist', 'skipOnError' => true, 'targetClass' => State::className(), 'targetAttribute' => ['state_id' => 'id']],
...@@ -69,7 +70,7 @@ class District extends \yii\db\ActiveRecord ...@@ -69,7 +70,7 @@ class District extends \yii\db\ActiveRecord
{ {
return [ return [
'id' => Yii::t('common', 'ID'), 'id' => Yii::t('common', 'ID'),
'state_id' => Yii::t('common', 'State ID'), 'state_id' => Yii::t('common', 'State'),
'name' => Yii::t('common', 'Name'), 'name' => Yii::t('common', 'Name'),
'slug' => Yii::t('common', 'Slug'), 'slug' => Yii::t('common', 'Slug'),
'status' => Yii::t('common', 'Status'), 'status' => Yii::t('common', 'Status'),
......
...@@ -53,6 +53,7 @@ class State extends \yii\db\ActiveRecord ...@@ -53,6 +53,7 @@ class State extends \yii\db\ActiveRecord
{ {
return [ return [
[['name'], 'required'], [['name'], 'required'],
[['name'], 'unique'],
[['status', 'created_at', 'updated_at'], 'integer'], [['status', 'created_at', 'updated_at'], 'integer'],
[['name', 'slug'], 'string', 'max' => 1024], [['name', 'slug'], 'string', 'max' => 1024],
]; ];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment