ThinkPHP增删改查--改

1.CURD 控制器
?>
namespace Home\Controller;

use Think\Controller;
class CurdController extends Controller{
public function index(){
$db_student = D('Student');
$data_student = $db_student->relation(true)->select();
// dump($data_student);
$this->assign('data',$data_student);
$this->display();
}
// public function extends
}

2.cued控制器html页面





修改实例




















序号

姓名

性别

创建时间

班级编号

操作

{$vo['id']}

{$vo.name}



{$vo.create_time}

{$vo['class'].class_name}

编辑





3.edit控制器
/**
* Created by 郭鹏.
* User: msi
* Date: 2017/12/15
* Time: 12:41
*/

namespace Home\Controller;


use Think\Controller;

class EditController extends Controller{
public function Edit(){
if(IS_GET) {
// dump(I('get.'));
$id = I('get.id');
$db_class = M('Class');
$db_student = M('Student');

$data_class = $db_class->select();
$data_student = $db_student->where('id = ' . $id)->find();
// dump($data_student);
$this->assign('class', $data_class);
$this->assign('student', $data_student);

$this->display('index');
}
}
public function editpost(){
if (IS_POST){
$data = I('post.');
$db_student = M('Student');
dump($data);
// $data['name'] = $_POST['name'];
// $data['sex'] = $_POST['sex'];
// $data['class_id'] = $_POST['class_id'];
$res = $db_student->save($data); // 根据条件更新记录
if($res) {
$this->success('恭喜你成功');
}else{
$this->success('修改失败');
}
}
}

}


4.获取信息页面并提交修改信息




Title



















序号

姓名

性别

创建时间

班级名称

{$student['id']}





















转载于:https://www.cnblogs.com/little-rock/p/8064047.html

你可能感兴趣的:(ThinkPHP增删改查--改)