先补一下课,没看过基本步骤的同学请看:
http://www.Vevb.com/cms/20141020/7505.html
下面开始第一个实例,企业服务模块,这是个比较简单的模块,做一个抛砖的作用.
模块功能分析:企业服务,企业填写招聘申请表,管理审核之后,展示作为招聘通知的功能.
■1.文件分布
modules文件夹和model文件夹,这是我们的文件范围,在modules下建立qiye这个文件夹.
地址:F:/www/phpcms/modules/qiye
■2.实例图
上面的文件作用,在之前第一篇文章已经介绍过了,这里我再说一下,index.php 和 qiyi.php 的作用,分别是前台和后台的控制器control.
■3.前台控制器 index.php,class名必须与文件名一致
地址:F:/www/phpcms/modules/qiye/index.php
- <?php
- defined('IN_PHPCMS') or exit('No permission resources.');
- class index {
- private $db,$ip;
- function __construct() {
- pc_base::load_app_func('global');
- $this->db = pc_base::load_model('qiye_model');
- $this->ip = ip();
- $siteid = isset($_GET['siteid']) ? intval($_GET['siteid']) : get_siteid();
- define("SITEID",$siteid);
- }
- public function init() {
- $siteid = SITEID;
- $page = intval($_GET['page'])<=0 ? 1 : intval($_GET['page']);
- include template('qiye', 'index');
- }
- public function lists() {
- $siteid = SITEID;
- $page = intval($_GET['page']);
- $page = max($page,1);
- $r = $this->db->select(array('siteid'=>$siteid));
- if($r) extract($r);
- include template('qiye', 'list');
- }
- public function show(){
- $siteid = SITEID;
- $comid = intval($_GET['comid']);
- if(!$comid) showmessage(L('information_does_not_exist'),'blank');
- $r = $this->db->get_one(array('comid'=>$comid));
- if(!$r) showmessage(L('info_does_not_exists'),'blank');
- extract($r);
- include template('qiye', 'show');
- }
- public function reg(){
- if(isset($_POST['comname'])){
- //如果用户提交申请
- if($_POST['comname']==''){
- showmessage(L('qiye_noname'),"?m=qiye&c=index&a=reg&siteid=$siteid");
- }
- $db = pc_base::load_model('qiye_model');//加载模型
- //接收数据并存储
- $s = array();
- $num = array();
- $num = $_POST['zp_num'];
- $s['siteid'] = SITEID;
- $s['comname'] = safe_replace($_POST['comname']);
- $s['dw_name'] = safe_replace($_POST['dw_name']);
- $s['dw_department'] = safe_replace($_POST['dw_department']);
- $s['dw_area'] = safe_replace($_POST['dw_area']);
- $s['dw_property'] = safe_replace($_POST['dw_property']);
- $s['dw_economic'] = safe_replace($_POST['dw_economic']);
- $s['dw_contact'] = safe_replace($_POST['dw_contact']);
- $s['dw_zipcode'] = safe_replace($_POST['dw_zipcode']);
- $s['dw_address'] = safe_replace($_POST['dw_address']);
- $s['dw_telphone'] = safe_replace($_POST['dw_telphone']);
- $s['dw_fax'] = safe_replace($_POST['dw_fax']);
- $s['dw_email'] = safe_replace($_POST['dw_email']);
- $s['zp_hr'] = safe_replace($_POST['zp_hr']);
- $s['zp_tel'] = safe_replace($_POST['zp_tel']);
- $s['zp_email'] = safe_replace($_POST['zp_email']);
- $s['zp_property'] = safe_replace($_POST['zp_property']);
- $s['zp_industry'] = safe_replace($_POST['zp_industry']);
- $s['zp_post'] = safe_replace($_POST['zp_post']);
- $s['zp_area'] = safe_replace($_POST['zp_area']);
- $s['zp_major'] = safe_replace($_POST['zp_major']);
- $s['zp_salary'] = safe_replace($_POST['zp_salary']);
- $s['zp_num'] = array2string($num);
- $s['attr_commercial'] = safe_replace($_POST['attr_commercial']);
- $s['attr_information'] = safe_replace($_POST['attr_information']);
- $s['url'] = 'index.php?m=qiye&c=index&a=show&id=`id`';
- $s['ip'] = $this->ip;
- $s['inputtime'] = SYS_TIME;
- $s['updatetime'] = SYS_TIME;
- $comid = $db->insert($s,true);
- if($comid){
- showmessage(L('qiye_success'), "?m=qiye&c=index&a=init&siteid=$siteid");
- }
- } else {
- //默认显示申请页面
- pc_base::load_sys_class('form', '', 0);
- $SEO = seo(SITEID, '', L('qiye_apply'), '', '');
- include template('qiye', 'register');
- }
- }
- }
- ?>
■4.后台控制器 qiye.php,class名必须与文件名一致.
地址:F:/www/phpcms/modules/qiye/qiye.php
新闻热点
疑难解答