Home>Article>PHP Framework> Implementation of department management functions

Implementation of department management functions

WJ
WJ forward
2020-06-09 17:02:22 3354browse

Implementation of department management functions

[1] Department list display

Analysis:

①控制器DeptController.class.php ②方法showList(不要使用list方法,因为list是关键词) ③模板文件:showList.html

Follow the steps to write

①Create the method showList to display the template

class DeptController extends Controller{ public function showList(){ $this->display(); } }

②Copy the template file showList.html to View/Dept (because the controller is Dept and the method is showList, so there must be a one-to-one correspondence)

③Modify the static resource path

④Revise the showList method to obtain department data. And passed to the template

public function showList(){ $model = M('dept');//模型实例化 $data = $model->order('sort asc')->select();//条件查询,升序排列 $this->assign('data',$data);//变量分配传递到模板 $this->display(); }

⑤ Template traverses to read data

 
id部门所属部门排序备注编辑数据删除数据
{$vol.id} {$vol.name} 顶级部门 二级部门 {$vol.sort} {$vol.remark} 编辑 删除

Note: 1. Spaces must be added to the if judgment of the template

0715519a642ebda1b568b1cd276de835Top-level department0e19ae19f9bb3871b7693b46538542ae

2.9de3db33131318b3291f7cdc0a95a15aAdd/

【二】Department Editor

Analysis:

Controller:DeptController.class.php

Method: edit (display template】process submission)

Template: edit.html

Write the code step by step

(1) Write the edit method to realize template display

public function edit(){ //展示模板 $this->display(); }

(2) Modify the edit button and bring the id when jumping to the page

编辑

(3) Copy the template file edit.html to the specified location,Admin/View/Dept/edit.html; Modify the static resource path

(4) Modify the edit method to display the original data

id:
部门:
所属部门:
排序:
备注:

(5) Process the form submission page

Hidden field: Because system restrictions cannot perform batch modification, the primary key must be specified when modifying. Therefore, a hidden field must be added to pass the id

id:
部门:
所属部门:
排序:
备注:

jquery submission:

(6) Saving of data, modifying the code after editing the edit method

public function edit(){//展示模板或者post请求 if (IS_POST){ $post = I('post.'); // dump($post);die; $model = M('dept'); //保存操作 $result = $model->save($post); if ($result !== false) { $this->success('修改成功',U('showList'),3); }else{ $this->error('修改失败'); } }else{ //接收id $id=I('get.id'); //实例化模型 $model = M('dept'); //查询指定记录 $data = $model->find($id); // 查询全部的部门信息(不包含当前级),同于下拉。因为包含自己所在级别会在递归时陷入死循环? $info = $model->where('id != '.$id)->select(); //变量分配 $this->assign('data',$data); $this->assign('info',$info); //展示模板 $this->display(); } }

[3] Department Delete

Analysis

Controller:DeptController.class.php

Method: del

Template: Delete no template required File, because deletion is a data processing process. Same as logging out

Note: There are single deletions and batch deletions. Editing can only be done individually, not in batches.

(1) Modify the template and add a check box

       
       
          >
          
id 部门 所属部门 排序 备注 编辑数据 删除
{$vol.id} {$vol.name} 顶级部门 二级部门 {$vol.sort} {$vol.remark}编辑

(2) Click the delete button to achieve deletion

①Click delete to get the value of the check box (jquery accomplish). Then go to the php deletion method

②Write the del method to achieve deletion

//True deletion---batch and single deletion

public function del(){ //接收参数 $id = I('get.id'); //模型实例化 $model = M('dept'); //删除 $result = $model->delete($id); //判断结果,删除成功或失败都会跳转到列表页,所以不用加入跳转链接 if ($result) { $this->success('删除成功'); }else{ $this->error('删除失败'); } }

The above is the ThinkPHP department All management functions.

Related references:thinkphp tutorial

The above is the detailed content of Implementation of department management functions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:51dev.com. If there is any infringement, please contact admin@php.cn delete