本文实例讲述了thinkPHP通用控制器实现方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
<?php namespace 目录\Controller; class TypeController extends Controller { public function add() { if (IS_POST) { $model = D( 'Type' ); if ( $model ->create()) { if ( $model ->add()) { $this ->success( '添加成功!' , U( 'lst' )); exit ; } else { $sql = $model ->getLastSql(); $this ->error( '插入数据库失败!.<hr />SQL:' . $sql ); } } else { $error = $model ->getError(); $this ->error( $error ); } } $this ->display(); } public function lst() { $model = D( 'Type' ); $data = $model ->search(); $this ->assign( $data ); $this ->display(); } public function save( $id ) { $model = D( 'Type' ); if (IS_POST) { if ( $model ->create()) { if ( $model ->save() !== FALSE) { $this ->success( '修改成功!' , U( 'lst' )); exit ; } else { $sql = $model ->getLastSql(); $this ->error( '修改数据库失败!.<hr />SQL:' . $sql ); } } else { $error = $model ->getError(); $this ->error( $error ); } } $data = $model ->find( $id ); $this ->assign( 'data' , $data ); $this ->display(); } public function del( $id ) { $model = D( 'Type' ); $model -> delete ( $id ); $this ->success( '操作成功!' , U( 'lst' )); } public function bdel() { $delid = I( 'post.delid' ); if ( $delid ) { $delid = implode( ',' , $delid ); $model = D( 'Type' ); $model -> delete ( $delid ); } else $this ->error( '请选择要删除的记录!' ); $this ->success( '操作成功!' , U( 'lst' )); } } |
希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。
原文链接:http://www.cnblogs.com/chenqionghe/p/4350001.html