Controller
<?php
/**
* This is the template for generating a controller class file.
* The following variables are available in this template:
* - $this: the ControllerCode object
*/
?>
<?php echo "<?php\n"; ?>
class <?php echo $this->controllerClass; ?> extends BaseController
{
//首页
public function actionIndex()
{
$this->layout = '//layouts/gridPage';
$this->render('index');
}
//新增视图
public function actionCreateView()
{
$this->renderPartial('create');
}
//新增操作
public function actionCreate()
{
$o<?php echo substr($this->controllerClass,0,-10); ?> = new <?php echo substr($this->controllerClass,0,-10); ?>();
$o<?php echo substr($this->controllerClass,0,-10); ?>->attributes = $_POST['<?php echo substr($this->controllerClass,0,-10); ?>'];
if ($o<?php echo substr($this->controllerClass,0,-10); ?>->save())
$this->Json(array('st' => true, 'msg' => '操作成功'));
else {
$this->Json(array('st' => false, 'msg' => CHtml::errorSummary($o<?php echo substr($this->controllerClass,0,-10); ?>)));
}
}
//查询
public function actionSearch()
{
$aPageData = <?php echo substr($this->controllerClass,0,-10); ?>::model()->PageList($_POST["PageIndex"], $_POST["PageSize"], $_POST['CodeName']);
$this->JsonGrid($aPageData);
}
//编辑视图
public function actionEditView()
{
$aModel = <?php echo substr($this->controllerClass,0,-10); ?>::model()->findByPk($_GET['iAutoID']);
$this->renderPartial('edit', array(
'aModel' => $aModel,
));
}
//编辑操作
public function actionEdit()
{
$bResult = <?php echo substr($this->controllerClass,0,-10); ?>::model()->updateByPk($_GET['iAutoID'], $_POST['<?php echo substr($this->controllerClass,0,-10); ?>']);
if ($bResult)
$this->Json(array('st' => true, 'msg' => '操作成功'));
else {
$this->Json(array('st' => false, 'msg' => CHtml::errorSummary(<?php echo substr($this->controllerClass,0,-10); ?>::model())));
}
}
//删除
public function actionDelete()
{
$bResult = <?php echo substr($this->controllerClass,0,-10); ?>::model()->deleteByPk($_POST["ids"]);
if ($bResult)
$this->Json(array('st' => true, 'msg' => '操作成功'));
else {
$this->Json(array('st' => false, 'msg' => CHtml::errorSummary(<?php echo substr($this->controllerClass,0,-10); ?>::model())));
}
}
}
Create
<?php
/**
* The following variables are available in this template:
* - $this: the CrudCode object
*/
?>
/* 此easyUI create由GII工具自动生成 */
/* 生成时间:<?php echo date('Y-m-d H:i:s'); ?>*/
<?php
$aColumn = [];
foreach ($this->tableSchema->columns as $column) {
if (!in_array($column->name, ['iAutoID', 'iCreateTime', 'iUpdateTime'])) {
$aColumn[] = [
'name' => $column->name,
'type' => $column->type,
'comment' => $column->comment,
];
}
}
?>
<?php echo "<?php "; ?>$form = $this->beginWidget('CActiveForm'); <?php echo "?>\n"; ?>
<table class="edittable">
<?php
foreach (array_chunk($aColumn, 2) as $aValTr) {
?>
<tr>
<?php foreach ($aValTr as $aValTd) { ?>
<td class="editor-label" style="width: 10%">
<?php echo " " . $aValTd['comment'] . "\n " ?>
</td>
<?php if ($aValTd['type'] == 'string') { ?>
<td class="editor-field" style="width: 90%">
<?php echo "<?php \n"; ?>
$this->widget('ext.yii-easyui.widgets.EuiValidateBox', array(
'required' => true,
'name' => '<?php echo $this->getModelClass(); ?>[<?php echo($aValTd['name']) ?>]'
));
<?php echo "?>"; ?>
</td>
<?php } else if ($aValTd['type'] == 'integer' && substr($aValTd['name'], -4) != 'Time' && substr($aValTd['comment'], -3) != 'bit') { ?>
<td class="editor-field" style="width: 90%">
<?php echo " <?php \n"; ?>
echo $form->dropDownList($oModel, '<?php echo($aValTd['name']) ?>', [], array('style' =>'width:175px;'))
<?php echo " ?>"; ?>
</td>
<?php } else if ($aValTd['type'] == 'integer' && substr($aValTd['name'], -4) == 'Time' && substr($aValTd['comment'], -3) != 'bit') { ?>
<td class="editor-field" style="width: 90%">
<?php echo " <?php \n"; ?>
$this->widget('ext.yii-easyui.widgets.EuiDatebox', array(
'name' => '<?php echo $this->getModelClass(); ?>[<?php echo($aValTd['name']) ?>]',
'validtype'=>'date',
'isValidate'=>'true',
'width'=>'200px;'
));
<?php echo " ?>"; ?>
</td>
<?php } else if ($aValTd['type'] == 'integer' && substr($aValTd['comment'], -3) == 'bit') { ?>
<td class="editor-field" style="width: 90%">
<?php echo " <?php \n"; ?>
echo CHtml::radioButtonList('<?php echo $this->getModelClass(); ?>[<?php echo($aValTd['name']) ?>]','1',array('1' => '是', '0' => '否'),array('separator'=>''))
<?php echo " ?>"; ?>
<?php } ?>
<?php } ?>
</tr>
<?php } ?>
</table>
<?php echo "<?php "; ?>$this->endWidget(); <?php echo "?>\n"; ?>
Edit
<?php
/**
* The following variables are available in this template:
* - $this: the CrudCode object
*/
?>
/* 此easyUI edit由GII工具自动生成 */
/* 生成时间:<?php echo date('Y-m-d H:i:s'); ?>*/
<?php
$aColumn = [];
foreach ($this->tableSchema->columns as $column) {
if (!in_array($column->name, ['iAutoID', 'iCreateTime', 'iUpdateTime'])) {
$aColumn[] = [
'name' => $column->name,
'type' => $column->type,
'comment' => $column->comment,
];
}
}
?>
<?php echo "<?php "; ?>$form = $this->beginWidget('CActiveForm'); <?php echo "?>\n"; ?>
<table class="edittable">
<?php
foreach (array_chunk($aColumn, 2) as $aValTr) {
?>
<tr>
<?php foreach ($aValTr as $aValTd) { ?>
<td class="editor-label" style="width: 10%">
<?php echo " " . $aValTd['comment'] . "\n " ?>
</td>
<?php if ($aValTd['type'] == 'string') { ?>
<td class="editor-field" style="width: 90%">
<?php echo "<?php\n"; ?>
$this->widget('ext.yii-easyui.widgets.EuiValidateBox', array(
'required' => true,
'name' => '<?php echo $this->getModelClass(); ?>[<?php echo($aValTd['name']) ?>]',
'value'=>$aModel['<?php echo($aValTd['name']) ?>']
));
<?php echo "?>\n"; ?>
</td>
<?php } else if ($aValTd['type'] == 'integer' && substr($aValTd['name'], -4) != 'Time' && substr($aValTd['comment'], -3) != 'bit') { ?>
<td class="editor-field" style="width: 90%">
<?php echo "<?php\n"; ?>
echo $form->dropDownList($oModel, '<?php echo($aValTd['name']) ?>', [], array('style' => 'width:175px;'))
<?php echo "?>\n"; ?>
</td>
<?php } else if ($aValTd['type'] == 'integer' && substr($aValTd['name'], -4) == 'Time' && substr($aValTd['comment'], -3) != 'bit') { ?>
<td class="editor-field" style="width: 90%">
<?php echo "<?php\n"; ?>
$this->widget('ext.yii-easyui.widgets.EuiDatebox', array(
'name' => '<?php echo $this->getModelClass(); ?>[<?php echo($aValTd['name']) ?>]',
'validtype'=>'date',
'isValidate'=>'true',
'width'=>'200px',
'value'=>date('Y-m-d',$aModel['<?php echo($aValTd['name']) ?>'])
));
<?php echo "?>\n"; ?>
</td>
<?php } else if ($aValTd['type'] == 'integer' && substr($aValTd['comment'], -3) == 'bit') { ?>
<td class="editor-field" style="width: 90%">
<?php echo "<?php\n"; ?>
echo CHtml::radioButtonList('<?php echo $this->getModelClass(); ?>[<?php echo($aValTd['name']) ?>]',$aModel['<?php echo($aValTd['name']) ?>'],array('1' => '是', '0' => '否'),array('separator'=>''))
<?php echo "?>\n"; ?>
<?php } ?>
<?php } ?>
</tr>
<?php } ?>
</table>
<?php echo "<?php "; ?>$this->endWidget(); <?php echo "?>\n"; ?>
Grid
<?php
/**
* The following variables are available in this template:
* - $this: the CrudCode object
*/
?>
<?php echo "<?php\n"; ?>
/* 此easyUI grid由GII工具自动生成 */
/* 生成时间:<?php echo date('Y-m-d H:i:s'); ?>*/
$this->widget('ext.yii-easyui.widgets.EuiDataGrid',
[
'id' => 'gvTable',
'url' => Yii::app()->createUrl("<?php echo (explode('/', $this->controller)[0]); ?>/LoginUser/search"),
'pagination' => true,
'rownumbers' => true,
'idField' => 'id',
'toolbar' => '#divToolbar',
'columns' => [
<?php
foreach($this->tableSchema->columns as $column)
{
if($column->autoIncrement){
?>
['field' => '<?php echo $column->name ?>', 'title' => '<?php echo $column->name ?>', 'width' => 100,'checkbox' => true],
<?php } else {?>
['field' => '<?php echo $column->name ?>', 'title' => '<?php echo $column->name ?>', 'width' => 100],
<?php }?>
<?php
}
?>
]
]
);
<?php echo "?>\n"; ?>
Index
<?php
/**
* The following variables are available in this template:
* - $this: the CrudCode object
*/
?>
<?php echo "<?php\n"; ?>
/* 此easyUI index由GII工具自动生成 */
/* 生成时间:<?php echo date('Y-m-d H:i:s'); ?>*/
$this->beginContent('//layouts/gridToolBar');
//新增按钮
$this->widget('ext.yii-easyui.widgets.EuiLinkButton', array(
'id' => 'lbtCreate',
'text' => '新增',
'iconCls' => 'icon-add',
'width' => '400',
'height' => '350',
'code' => 0,
'url' => Yii::app()->createUrl("<?php echo (explode('/', $this->controller)[0]); ?>/<?php echo $this->getModelClass(); ?>/CreateView")
));
//编辑按钮
$this->widget('ext.yii-easyui.widgets.EuiLinkButton', array(
'id' => 'lbtEdit',
'text' => '编辑',
'iconCls' => 'icon-edit',
'width' => '580',
'height' => '350',
'enabled_state' => 80, //只能选一条数据
'url' => Yii::app()->createUrl("<?php echo (explode('/', $this->controller)[0]); ?>/<?php echo $this->getModelClass(); ?>/EditView"),
'disabled' => true,
'code' => 0,
));
//删除按钮
$this->widget('ext.yii-easyui.widgets.EuiLinkButton', array(
'id' => 'lbtDelete',
'text' => '删除',
'iconCls' => 'icon-remove',
'url' => Yii::app()->createUrl("<?php echo (explode('/', $this->controller)[0]); ?>/<?php echo $this->getModelClass(); ?>/Delete"),
'enabled_state' => 16, //一条或多条
'disabled' => true,
'code' => 0
));
<?php echo "?>\n"; ?>
<!--查询-->
<div style="float: right;">
<input type="text" placeholder="名称" id="CodeName" name="CodeName">
<?php echo "<?php\n"; ?>
$this->widget('ext.yii-easyui.widgets.EuiLinkButton', array(
'id' => 'lbtSearch',
'text' => '查询',
'iconCls' => 'icon-search',
'url' => Yii::app()->createUrl("<?php echo (explode('/', $this->controller)[0]); ?>/<?php echo $this->getModelClass(); ?>/Search"),
'search_for' => '#CodeName'
));
<?php echo "?>\n"; ?>
</div>
<?php echo "<?php"; ?> $this->endContent(); <?php echo "?>\n"; ?>
<?php echo "<?php"; ?> $this->renderPartial('grid'); <?php echo "?>\n"; ?>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
jQuery.InitializeDataGridPage({
watermark: "#CodeName"
});
});
</script>