计算机科学与技术1班邵立敏

发布时间 : 星期六 文章计算机科学与技术1班邵立敏更新完毕开始阅读

潍 坊 学 院 本 科 毕 业 设 计

图4.15 教师添加

部分代码如下: //老师列表

public function teacherList(){

import('ORG.Util.Page');// 导入分页类 if($this->isPost()){

$teacher_personId = $this->_param('teacher_personId'); $Where=\ $count = M('teacher')->where($Where)->count();

$Page = new Page($count,100);// 实例化分页类 传入总记录数和每页显示的记录数 $show = $Page->show();// 分页显示输出

// 进行分页数据查询 注意limit方法的参数要使用Page类的属性 $list=M('teacher')->where($Where)->order('teacher_id desc')->limit($Page->firstRow.','.$Page->listRows)->select(); }else{

$count = M('teacher')->count();// 查询满足要求的总记录数

$Page = new Page($count,100);// 实例化分页类 传入总记录数和每页显示的记录数 $show = $Page->show();// 分页显示输出

// 进行分页数据查询 注意limit方法的参数要使用Page类的属性

30

潍 坊 学 院 本 科 毕 业 设 计

$list=M('teacher')->order('teacher_id

desc')->limit($Page->firstRow.','.$Page->listRows)->select(); }

$this->assign('page',$show);// 赋值分页输出 $this->assign(\ $this->display(); }

//添加老师账号

public function teacherAdd(){ if($this->isPost()){

$teacher_personId = $this->_param('teacher_personId'); $teacher_password = md5($this->_param('teacher_password')); $teacher_name = $this->_param('teacher_name');

$parent = M('teacher') ->where(array('teacher_parentId'=>$teacher_parentId))->find(); if(!empty($user)){

$this->error('该老师帐号已存在'); exit(); }

if(empty($teacher_personId) || empty($teacher_password)){ $this->error('账号与密码不能为空'); exit(); }

if(empty($teacher_name)){ $this->error('姓名不能为空'); exit(); }

$data=array(

'teacher_name' => $teacher_name, 'teacher_personId' => $teacher_personId, 'teacher_password' => $teacher_password, 'teacher_time' => time(), );

$id=M('teacher') ->data($data) ->add();

31

潍 坊 学 院 本 科 毕 业 设 计

if($id){

$this -> success('添加成功',U('teacherList')); }else{

$this->error('添加失败'); } }else{

$this->display(); } }

//修改老师信息

public function teacherEdit(){

$teacher_id = $this->_param('teacher_id');

$info = M('teacher')->where(array('teacher_id'=>$teacher_id))->find(); if($this->isPost()){

$teacher_personId = $this->_param('teacher_personId'); $teacher_password = trim($this->_param('teacher_password')); $teacher_name = $this->_param('teacher_name'); if(empty($teacher_password)){

$teacher_password = $info['teacher_password']; }else{

$teacher_password = md5($teacher_password); }

$data=array(

'teacher_name' => $teacher_name, 'teacher_personId' => $teacher_personId, 'teacher_password' => $teacher_password, );

$id=M('teacher')->where(array('teacher_id'=>$teacher_id)) ->save($data); if($id !== false){

$this -> success('修改成功',U('teacherList')); }else{

$this->error('修改失败'); }

32

潍 坊 学 院 本 科 毕 业 设 计

}else{

$this->assign(\ $this->display(); } } }

4.2.8 分类的添加及修改

管理员可以对新闻的分类进行添加和修改,增加了内容的多样性。

图4.16分类的添加

部分代码如下:

//修改栏目

public function update(){

$id = $this->_param('id');//栏目id if($this->isGet()){

$data=M('column')->where(array('id'=>$id))->find();

$info=M('category')->where(array('pid'=>1,'deleteFlag'=>1))->select(); $this->assign('data',$data); $this->assign('info',$info); $this->display(); }elseif($this->isPost()){

$flag=$this->_param('flag');//1系统 2手动

33

联系合同范文客服:xxxxx#qq.com(#替换为@)