PHPCMS 房产模块 二次开发 第二天
PHPCMS 二次开发 房产模块
今天主要完成了楼盘的一些操作。
house/include/house.class.php
这个文件顾名思义,是一个CLASS文件。
大致内容如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?php
2 defined('IN_PHPCMS') or exit('Access Denied');
3
4 //house
5 class house
6 {
7 var$houseid;
8 var$db;
9
10 function house($houseid=0)
11 {
12 global$db;
13 $this->db =$db;
14 $this->houseid =intval($houseid);
15 }
16
17 //插入信息
18 function insert($info){
19 $this->db->insert($info);
20 returntrue;
21 }
22
23 //更新信息
24 function update($info,$houseid){
25 $houseid=$this->houseid;
26 $sql='';
27 if(!is_array($info)) returnfalse;
28 foreach($infoas$key=>$val)
29 {
30 $sql.="`$key`='$val',";
31 }
32 $sql=substr($sql,0,strlen($sql)-1);
33 $this->db->query("update ".DB_PRE."housing set $sql where housingid = $houseid");
34 return$houseid;
35 }
36
37 // 删除楼盘
38 function delete($houseids)
39 {
40 $houseids=is_array($houseids) ?implode(',',$houseids) :intval($houseids);
41 $this->db->query("DELETE FROM ".DB_PRE."housing WHERE housingid in($houseids)");
42 returntrue;
43 }
44 ?>
45
2 defined('IN_PHPCMS') or exit('Access Denied');
3
4 //house
5 class house
6 {
7 var$houseid;
8 var$db;
9
10 function house($houseid=0)
11 {
12 global$db;
13 $this->db =$db;
14 $this->houseid =intval($houseid);
15 }
16
17 //插入信息
18 function insert($info){
19 $this->db->insert($info);
20 returntrue;
21 }
22
23 //更新信息
24 function update($info,$houseid){
25 $houseid=$this->houseid;
26 $sql='';
27 if(!is_array($info)) returnfalse;
28 foreach($infoas$key=>$val)
29 {
30 $sql.="`$key`='$val',";
31 }
32 $sql=substr($sql,0,strlen($sql)-1);
33 $this->db->query("update ".DB_PRE."housing set $sql where housingid = $houseid");
34 return$houseid;
35 }
36
37 // 删除楼盘
38 function delete($houseids)
39 {
40 $houseids=is_array($houseids) ?implode(',',$houseids) :intval($houseids);
41 $this->db->query("DELETE FROM ".DB_PRE."housing WHERE housingid in($houseids)");
42 returntrue;
43 }
44 ?>
45
house/admin/house.inc.php
大致内容如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?php
2 defined('IN_PHPCMS') or exit('Access Denied');
3
4 $keyid=$keyid?$keyid:'phpcms';
5 $action=$action?$action:'manage';
6
7 switch($action)
8 {
9 case'add':// 添加楼盘
10 {
11 if(isset($dosubmit))
12 {
13 //接受字段处理
14 if(empty($houseinfo['housingname'])) showmessage($LANG['housename']);
15 $houseinfo['adduserid'] =intval($_userid);
16 $houseinfo['addedtime'] =TIME;
17 http://5igo.net.cn
18 //执行数据库操作
19 $admin_house->insert($houseinfo);
20 }
21 else
22 {
23 include admin_tpl('add');
24 }
25 }
26 break;
27
28 case'delete':// 删除楼盘
29 {
30 if(empty($houseids))
31 {
32 showmessage('请先选择要删除的楼盘!');
33 }
34 $admin_house->delete($houseids);
35 showmessage($LANG['operation_success'],$forward);
36 }
37 break;
38
39 case'edit'://修改楼盘
40 {
41 if(isset($submit))
42 {
43 //接受字段处理
44 if(empty($houseinfo['housingname'])) showmessage($LANG['housename']);
45 $houseinfo['adduserid'] =intval($_userid);
46 $houseinfo['updatedtime'] =TIME;
47
48 //执行数据库操作
49 $admin_house->update($houseinfo,$houseid);
50 }else{
51 if(empty($subjectid))
52 {
53 showmessage('错误:找不到对应的楼盘信息,请先选择楼盘!');
54 }
55 $houseinfo=$admin_house->get_info($subjectid,'housingid');
56 include admin_tpl('edit');
57 }
58 }
59 break;
60 }
2 defined('IN_PHPCMS') or exit('Access Denied');
3
4 $keyid=$keyid?$keyid:'phpcms';
5 $action=$action?$action:'manage';
6
7 switch($action)
8 {
9 case'add':// 添加楼盘
10 {
11 if(isset($dosubmit))
12 {
13 //接受字段处理
14 if(empty($houseinfo['housingname'])) showmessage($LANG['housename']);
15 $houseinfo['adduserid'] =intval($_userid);
16 $houseinfo['addedtime'] =TIME;
17 http://5igo.net.cn
18 //执行数据库操作
19 $admin_house->insert($houseinfo);
20 }
21 else
22 {
23 include admin_tpl('add');
24 }
25 }
26 break;
27
28 case'delete':// 删除楼盘
29 {
30 if(empty($houseids))
31 {
32 showmessage('请先选择要删除的楼盘!');
33 }
34 $admin_house->delete($houseids);
35 showmessage($LANG['operation_success'],$forward);
36 }
37 break;
38
39 case'edit'://修改楼盘
40 {
41 if(isset($submit))
42 {
43 //接受字段处理
44 if(empty($houseinfo['housingname'])) showmessage($LANG['housename']);
45 $houseinfo['adduserid'] =intval($_userid);
46 $houseinfo['updatedtime'] =TIME;
47
48 //执行数据库操作
49 $admin_house->update($houseinfo,$houseid);
50 }else{
51 if(empty($subjectid))
52 {
53 showmessage('错误:找不到对应的楼盘信息,请先选择楼盘!');
54 }
55 $houseinfo=$admin_house->get_info($subjectid,'housingid');
56 include admin_tpl('edit');
57 }
58 }
59 break;
60 }
house/admin/templates/add.tpl.php
大致内容如下:
略
路径分析:?mod=house&file=house&action=manage&.....
mod 模块文件夹
file 模块下admin里面的house.inc.php
action 模块中inc文件里面的操作