Skip to content
This repository has been archived by the owner on Jan 18, 2019. It is now read-only.

Commit

Permalink
state crud #8 #13
Browse files Browse the repository at this point in the history
  • Loading branch information
Vikas Yadav committed Sep 28, 2017
1 parent 0829f11 commit 5e7ab9c
Show file tree
Hide file tree
Showing 9 changed files with 670 additions and 0 deletions.
173 changes: 173 additions & 0 deletions protected/controllers/StateController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php

class StateController extends Controller
{
/**
* @var string the default layout for the views. Defaults to '//layouts/column2', meaning
* using two-column layout. See 'protected/views/layouts/column2.php'.
*/
public $layout='//layouts/column2';

/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
);
}

/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}

/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}

/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new State;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['State']))
{
$model->attributes=$_POST['State'];
if($model->save())
$this->redirect(array('view','id'=>$model->id_state));
}

$this->render('create',array(
'model'=>$model,
));
}

/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model=$this->loadModel($id);

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['State']))
{
$model->attributes=$_POST['State'];
if($model->save())
$this->redirect(array('view','id'=>$model->id_state));
}

$this->render('update',array(
'model'=>$model,
));
}

/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
$this->loadModel($id)->delete();

// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}

/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('State');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}

/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new State('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['State']))
$model->attributes=$_GET['State'];

$this->render('admin',array(
'model'=>$model,
));
}

/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer $id the ID of the model to be loaded
* @return State the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model=State::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}

/**
* Performs the AJAX validation.
* @param State $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='state-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}
130 changes: 130 additions & 0 deletions protected/views/state/_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
/* @var $this StateController */
/* @var $model State */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'state-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>

<?php echo $form->errorSummary($model); ?>

<div class="row">
<?php echo $form->labelEx($model,'ST_CODE'); ?>
<?php echo $form->textField($model,'ST_CODE'); ?>
<?php echo $form->error($model,'ST_CODE'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'name'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'ias_short_code'); ?>
<?php echo $form->textField($model,'ias_short_code',array('size'=>2,'maxlength'=>2)); ?>
<?php echo $form->error($model,'ias_short_code'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'id_census'); ?>
<?php echo $form->textField($model,'id_census'); ?>
<?php echo $form->error($model,'id_census'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'eci_ref'); ?>
<?php echo $form->textField($model,'eci_ref',array('size'=>3,'maxlength'=>3)); ?>
<?php echo $form->error($model,'eci_ref'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'session_from'); ?>
<?php echo $form->textField($model,'session_from'); ?>
<?php echo $form->error($model,'session_from'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'session_to'); ?>
<?php echo $form->textField($model,'session_to'); ?>
<?php echo $form->error($model,'session_to'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'lok_parl_seats'); ?>
<?php echo $form->textField($model,'lok_parl_seats'); ?>
<?php echo $form->error($model,'lok_parl_seats'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'amly_seats'); ?>
<?php echo $form->textField($model,'amly_seats'); ?>
<?php echo $form->error($model,'amly_seats'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'raj_parl_seats'); ?>
<?php echo $form->textField($model,'raj_parl_seats'); ?>
<?php echo $form->error($model,'raj_parl_seats'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'updated'); ?>
<?php echo $form->textField($model,'updated'); ?>
<?php echo $form->error($model,'updated'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'iso3166'); ?>
<?php echo $form->textField($model,'iso3166',array('size'=>3,'maxlength'=>3)); ?>
<?php echo $form->error($model,'iso3166'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'psloc'); ?>
<?php echo $form->textField($model,'psloc'); ?>
<?php echo $form->error($model,'psloc'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'eci_dist_count'); ?>
<?php echo $form->textField($model,'eci_dist_count'); ?>
<?php echo $form->error($model,'eci_dist_count'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'eci_amly_count'); ?>
<?php echo $form->textField($model,'eci_amly_count'); ?>
<?php echo $form->error($model,'eci_amly_count'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'slug'); ?>
<?php echo $form->textField($model,'slug',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'slug'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'mcorp_count'); ?>
<?php echo $form->textField($model,'mcorp_count'); ?>
<?php echo $form->error($model,'mcorp_count'); ?>
</div>

<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
Loading

0 comments on commit 5e7ab9c

Please sign in to comment.