在index模块的Student控制中,需要写两个方法
- 显示添加页面
- 提交表单,添加记录
参考代码如下:
<?php
namespace app\index\controller;
use app\common\controller\AdminBase;
use think\Db;
use think\exception\PDOException;
/**
* 学生控制器
* 主要实现学生的添加、修改、删除、显示
*/
class Student extends AdminBase
{
//显示添加学生的页面
public function add()
{
return $this->fetch();
}
//执行添加操作
public function do_add()
{
$data = input('post.');
try {
$ret = Db::name('student')->insert($data);
$this->success('添加成功', 'all');
} catch (PDOException $ex) {
$this->error('添加失败,' . $ex->getMessage());
}
}
}
上面的这些代码,在前期的博客中已经讲过。