控制器的代码
<?php
namespace Admin\Controller;
use Think\Controller;
class HighLevelController extends BaseController {
public function add(){
$high_level=M('high_level');
if(IS_POST){
$data=I('post.');
print_r($data);
if($data['id']){
// 编辑
}else{
//添加
$res=$high_level->add($data);
print_r(M()->_sql());//打印SQL语句
if($res !==false){
echo 'OK';//$this->success('添加成功');
}else{
//$this->error('添加失败');
}
}
}else{
$this->display();
}
}
前端表单代码
<form class="form-horizontal m-t " method="post" action="{:U('add')}">
<!--<input type="hidden" id="id"/> -->
<div class="form-group">
<label class="col-sm-3 control-label">首页显示位置:</label>
<div class="col-sm-3">
<select name="layout">
<option value="left" <if condition="($data.layout eq 'left')"> selected</if>>左侧</option>
<option value="bottom" <if condition="($data.layout eq 'bottom')"> selected</if>>底部</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">名称:</label>
<div class="col-sm-3">
<input type="text" id="high_name" class="form-control" name="high_name" value="{$data.high_name}">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">排序:</label>
<div class="col-sm-3">
<input type="text" id="sort" class="form-control" name="sort" value="{$data.sort}">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">是否显示:</label>
<input type="radio" value="0" name="is_display" <if condition="($data.is_display neq 1)">checked </if> />
否
<input type="radio" value="1" name="is_display" <if condition="($data.is_display eq 1)">checked </if> />
是
</div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-3">
<button class="btn btn-primary" type="submit">提交</button>
</div>
</div>
</form>
</div>
</div>
</div>
<!--尾部-->
<include file="Common/admin:footer"/>
</div>
</block>