M 模型phpcms/modules 文件夹下面的目录名称
C 控制器phpcms/modules/模型文件夹下面的php文件,该文件名为控制器名称A 事件/方法phpcms/modules/模型/控制器.php 文件中的方法名称
http://localhost/myphpcms/index.php?m=customer&c=customer&a=cuastomer
m=customer phpcms/modules下面的customer文件夹
c=customer phpcms/modules/customer 文件夹下面的customer.php 文件
a=customer phpcms/modules/customer/customer.php 文件中的function customer() 方法
模版文件放在phpcms/modules/customer/templates 文件下
主要文件为customer.php 文件
一、customer.php主要方法有:
customer() 客户信息列表方法view()查看客户信息方法search()查询客户信息方法add() 添加客户信息方法edit() 修改客户信息方法delete()删除客户信息方法image() 客户图片上传方法get_linkage_fullname() 查看
1.customer() 客户信息列表方法
//获取搜索框中的查询值
$keyword = isset($_GET['keyword']) ? $_GET['keyword'] : '';
//获取查找类型(客户名称或是客户id)
$type = isset($_GET['type']) ? $_GET['type'] : '';
//获取查找的时间范围
$start_time = isset($_GET['start_time']) ? $_GET['start_time'] : '';
$end_time = isset($_GET['end_time']) ? $_GET['end_time'] : date('Y-m-d', SYS_TIME);
//添加客户的按钮(后面详细说明)
$big_menu=array('javascript:window.top.art.dialog({id:\'add\',iframe:\'?m=customer&c=c ustomer&a=add\', title:\''.L('customer_add').'\',width:\'700\',height:\'500\'}, function(){var d=window.top.art.dialog({id:\'add\'}).data.iframe;d.document.getElementById(\'dosubmit\' ).click();return false;}, function(){window.top.art.dialog({id:\'add\'}).close()});void(0);', L('customer_add'));
//传递显示的页数
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
//查询表中所有数据
$infos=$this->db->listinfo($where=’’,'cusid DESC', $page,5);
//传递页码条
$pages = $this->db->pages;
//现实到customer_list.tpl.php前台页面上
include $this->admin_tpl('customer_list');
2.view()查看客户信息方法
//根据客户的id号码查询对应客户的详细数据
$infos=$this->db->get_one(array('cusid'=>$_GET['cusid']));
//获取所属地区的所有缓存
$data = getcache('1','linkage');
$city = $this->get_linkage_fullname($infos['address'],$data);
$city = explode('>',$city);
$city = implode(',',$city);
$infos['address'] = rtrim($city,',');
//显示到customer_view.tpl.php模版上
include $this->admin_tpl('customer_view');
3.search()查询客户信息方法
$keyword = isset($_GET['keyword']) ? $_GET['keyword'] : '';
$type = isset($_GET['type']) ? $_GET['type'] : '';
$start_time = isset($_GET['start_time']) ? $_GET['start_time'] : '';
$end_time = isset($_GET['end_time']) ? $_GET['end_time'] : date('Y-m-d', SYS_TIME);
//点击搜索按钮以后执行
if (isset($_GET['search'])) {
//默认选取一个月内的用户,防止用户量过大给数据造成灾难
$where_start_time = strtotime($start_time) ? strtotime($start_time) : 0;
$where_end_time = strtotime($end_time) + 86400;
//开始时间大于结束时间,置换变量
if($where_start_time > $where_end_time) {
$tmp = $where_start_time;
$where_start_time = $where_end_time;
$where_end_time = $tmp;
$tmptime = $start_time;
$start_time = $end_time;
$end_time = $tmptime;
unset($tmp, $tmptime);
}
//组织sql语句中的where语句
$where = '';
//如果是超级管理员角色,显示所有用户,否则显示当前站点用户
if($_SESSION['roleid'] == 1) {
if(!empty($siteid)) {
$where .= "`siteid` = '$siteid' AND ";
}
} else {
$siteid = get_siteid();
$where .= "`siteid` = '$siteid' AND ";
}
// 根据传递过来的时间组织where语句
$where.= "`addtime` BETWEEN '$where_start_time' AND '$where_end_time' AND ";
//判断类型进行对应的模糊查找
if($keyword) {
if ($type == '1') {
$where .= "`cusname` LIKE '%$keyword%'";
} elseif($type == '2') {
$where .= "`cusid` = '$keyword'";
} else {
$where .= "`cusname` like '%$keyword%'";
}
} else {
$where .= '1';
}
} else {
//未点击搜索按钮的where语句
$where = '';
}
//重新搜索按钮
$big_menu=array('?m=customer&c=customer&a=customer', L('member_research'));
4.add() 添加客户信息方法
//点击确定按钮后
if(isset($_POST['dosubmit'])){
$info = $_POST['info']; //接收post传过来的info数组
$info['addtime'] = time(); //像数组增加添加时间数据
$this->db->insert($info); //将数组存储到数据库
}
//客户头像上传方法(后面详细介绍)
$image = $this->image('cusphoto','thumb','','customer');
//显示到customer_add.tpl.php模版上
include $this->admin_tpl('customer_add');
5.edit() 修改客户信息方法
if(isset($_POST['dosubmit'])){
//点击确认按钮后执行
//获取客户id,根据id对客户信息进行更改
$cusid = $_POST['cusid'];/
//修改的数据放入数组
$info = $_POST['info'];
//更改数据
if ($this->db->update($info,array('cusid'=>$cusid))) {
//更改成功执行
showmessage(L('operation_success'),
'?m=customer&c=customer&a=customer', '', 'edit');
} else {
//更改失败执行
showmessage(L('operation_failure'), HTTP_REFERER);
}
}else{
//打开修改窗口为进行修改时
//根据客户id进行数据查找并显示到customer_edit.tpl.php模板上
$infos=$this->db->get_one(array('cusid'=>$_GET['cusid']));
$image = $this->image('cusphoto','cusphoto',"$infos[cusphoto]",'customer');
include $this->admin_tpl('customer_edit');
}
6.delete()删除客户信息方法
//点击删除是获取选中的所有客户id,并对其进行where语句的组装
foreach($_POST['cusid'] as $v){
$where = array('cusid'=> $v);
$re = $this->db->delete($where);
}
//判断是否删除成功
if($re){
showmessage(L('operation_success'), HTTP_REFERER);
} else {
showmessage(L('operation_failure'), HTTP_REFERER);
}
7.image() 客户图片上传方法
function image($name, $id = '', $value = '', $moudle='', $catid='', $size = 50, $class = '', $ext = '', $alowexts = '',$thumb_setting = array(),$watermark_setting = 0 ) {
//$name 表单名称$id 表单id $value表单默认值及图片路径$moudle 模块名称$alowexts 允许图片格式
if(!$id) $id = $name; //如果没有id,默认设置id与表单名相同
if(!$size) $size= 50; //若果没有表单长度,默认为50
//查看图片设置是否为空,是否有长度
if(!empty($thumb_setting) && count($thumb_setting)) $thumb_ext = $thumb_setting[0].','.$thumb_setting[1];
else $thumb_ext = ',';
//如果未设置图片格式,默认为一下可是均可使用
if(!$alowexts) $alowexts = 'jpg|jpeg|gif|bmp|png';
//查看是否定义常量IMAGES_INIT
if(!defined('IMAGES_INIT')) {
//如果没有定义该常量,加载swf2ckeditor.js与content_addtop.js文件,并定义常量
$str='
';
define('IMAGES_INIT', 1);
}
//将$value进行htmlspecialchars函数处理
$value = new_html_special_chars($value);
//查看$value是否存在,如果如果不存在赋予默认值
$preview_img = $value ? $value : IMG_PA TH.'icon/upload-pic.png';
//生成上传图片验证
$authkey = upload_key("1,$alowexts,1,$thumb_ext,$watermark_setting");
//隐藏表单
$str.="
//图片链接地址。点击图片执行flashupload()函数
return $str;
}
function flashupload(uploadid, name, textareaid, funcName, args, module, catid, authkey) {
// uploadid,弹框的id,name弹框的名称textareaid表单的id, funcName成功时执行函数, module模块名称, catid栏目id, authkey上传图片验证
//组织跳转页
var args = args ? '&args='+args : '';
var setting = '&module='+module+'&catid='+catid+'&authkey='+authkey;
//弹框(后边会详细介绍)
window.top.art.dialog({title:name,id:uploadid,iframe:'index.php?m=attachment&c=attac hments&a=swfupload'+args+setting,width:'500',height:'420'},
//点击确定按钮执行
function(){ }
//查看是否存在funcName
if(funcName)
{
//存在就执行对应函数(此项目中此处函数为thumb_images)funcName.apply(this,[uploadid,textareaid]);}else
{submit_ckeditor(uploadid,textareaid);}},
//点击取消按钮执行,关闭弹框
function(){window.top.art.dialog({id:uploadid}).close()});
}
function thumb_images(uploadid,returnid) {
var d = window.top.art.dialog({id:uploadid}).data.iframe;
var in_content = d.$("#att-status").html().substring(1);
if(in_content=='') return false;
if(!IsImg(in_content)) {
alert('选择的类型必须为图片类型');
return false;
}
//查看图片的路径是否存在
if($('#'+returnid+'_preview').attr('src')) {
//如果存在将上传后图片路径替换原来路径
$('#'+returnid+'_preview').attr('src',in_content);
}
//将表单的值更改为上传后图片路径
$('#'+returnid).val(in_content);
}
8.get_linkage_fullname() 通过所属地区保存的linkageid获取名字路径
function get_linkage_fullname($linkageid, $linkagelist) {
//$linkageid 所属地区存储的最后一级linkageid,
//$linkagelist 全部所属地区的数组
$fullname = ''; //定义返回名称
//查看父id是否为0(是否是为第一级)
if($linkagelist['data'][$linkageid]['parentid'] != 0) {
//如果不是进行递归查找名称
$fullname = $this->get_linkage_fullname($linkagelist['data'][$linkageid]['parentid'], $linkagelist);
}
//还会所在地区名称字符串
$return = $fullname.$linkagelist['data'][$linkageid]['name'].'>';
return $return;
}
9.公共函数中的所属区域三级联动菜单
function menu_linkage($linkageid = 0, $id = 'linkid', $defaultvalue = 0){
//$linkageid联动菜单id,$id生成的联动菜单id,$defaultvalue菜单默认值
$linkageid = intval($linkageid);
$datas = array();
$datas = getcache($linkageid,'linkage'); //获取联动菜单的缓存数组
$infos = $datas['data']; //去除省市数组
//查看是否有默认值
$title = $defaultvalue ? $infos[$defaultvalue]['name'] : $datas['title'];
$colObj = random(3).date('is');
$string = '';
//是否定义了常量LINKAGE_INIT
if(!defined('LINKAGE_INIT')) {
//如果没定义,定义常量,并加载mln.colselect.js文件
define('LINKAGE_INIT', 1);
$string .= '';
//是否定义了常量IN_ADMIN
if(defined('IN_ADMIN')) {
//如果定义了,加载admin.css文件
$string .= '
rel="stylesheet" type="text/css">';
} else {
//如果没定义,定义常量,并加载css.css文件
$string .= '
type="text/css">';
}
}
//生成3级联动菜单
$string .= '
';$string .= '';
}
//返回联动菜单
return $string;
}
二、常用知识点
1.弹框函数window.top.art.dialog()
window.top.art.dialog({
id:\'add\', //弹框的id号
iframe:\'?m=customer&c=customer&a=add\', //弹框的链接页
title:\''.L('customer_add').'\',//弹框头部显示名称
width:\'700\',//弹框宽
height:\'500\'//弹框高},
//点击确认执行函数
function(){
var d=window.top.art.dialog({id:\'add\'}).data.iframe;
d.document.getElementById(\'dosubmit\').click();
return false;},
//点击取消执行函数
function(){window.top.art.dialog({id:\'add\'}).close()});
2.按钮$big_menu=array(')
//两个参数,第一个为按钮链接地址,第二个为按钮显示名称
$big_menu=array('?m=customer&c=customer&a=customer', L('member_research'));