您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

[PC]PHPCMS二次开发指南(上)

2024/3/16 4:28:46发布23次查看
-------------------------------------------------------------------------------------
phpcms本身功能已经很完善,自带的模块可用可不用,松耦合特性使其非常适合企业的二次开发。
pc的默认路由在 phpcms/caches/configs/route.php 中定义,为content模块下index控制器的init方法
一. pc所有模块都在module目录下,与数据表名字相同;
module目录中文件就是控制器,控制器名与文件名相同;
前台控制器如index.php无须继承任何类,用于前台操作;
后台控制器一般需要继承admin模块的admin类,一旦继承admin就需要权限验证(也可以不继承)。
二. 总结开发后台模块的步骤:
1. 后台访问扩展的模块:
扩展 - 菜单管理 - 添加菜单 - 上级:作为一级菜单(模块名,文件名,方法名)
添加子菜单 - 上级:某个一级菜单(填不存在的模块名,填不存在的文件名,填不存在的方法名)
扩展模块后,需要在v9_module中注册模块!(相当于安装)
2. 创建数据表:
create table v9_link( .........)engine=myisam default charset='utf8';
3. 建立后台的数据模型
php
defined('in_phpcms') or exit('no permiss resources.');pc_base::load_sys_class('model', '', 0);class link_model extends model { function __construct() { $this->db_config = pc_base::load_config('database'); $htis->db_setting = 'default'; $this->table_name = 'link'; parent::__construct(); } }/** * 几点注意: * 1. pc的数据模型基本是鸡肋,只是指定了数据库设置和对应的表名,非彻底的mvc,直接复制一份修改即可。 * 2. 此模型一般在控制器构造方法调用。
*/
4. 建立后台控制器:
php /** * 后台友情链接,完整curd */ defined('in_phpcms') or exit('no permission resources.'); pc_base::load_app_class('admin', 'admin', 0); class link extends admin { private $db, $admin_db; public $siteid; function __construct() { parent::__construct(); $this->m = new_html_special_chars(getcache('link', 'commons')); $this->db = pc_base::load_model('link_model'); $this->db2 = pc_base::load_model('type_model'); } /** * 友情链接列表 */ public function init() { if($_get['typeid'] != '') { $where = array('typeid'=>intval($_get['typeid']), 'siteid'=>$this->get_siteid()); } else { $where = array('siteid'=>$this->get_siteid()); } $page = (isset($_get['page']) && intval($_get['page'])) ? intval($_get['page']) : 1; $infos = $this->db->listinfo($where, $order = 'listorder desc, linkid desc', $page, $page = '9'); $pages = $this->db->pages; $types = $this->db2->listinfo(array('module'=>route_m, 'siteid'=>$this->get_siteid()), $order = 'typeid desc'); $types = new_html_special_chars($types); $type_arr = array(); foreach($types as $typeid=>$type) { $type_arr[$type['typeid']] = $type['name']; } $big_menu = array('javascript:window.top.art.dialog({id:\'add\',iframe:\'?m=link&c=link&a=add\', title:\''.l('link_add').'\', width:\'700\', height:\'450\'}, function(){var d = window.top.art.dialog({id:\'add\'}).data.iframe;var form = d.document.getelementbyid(\'dosubmit\');form.click();return false;}, function(){window.top.art.dialog({id:\'add\'}).close()});void(0);', l('link_add')); include $this->admin_tpl('link_list'); } /* 判断标题重复和验证 */ /* 添加分类时,验证分类名是否已存在 */ /** * 添加友情链接 */ public function add() { if(isset($_post['dosubmit'])) { $_post['link']['addtime'] = sys_time; $_post['link']['siteid'] = $this->get_siteid(); if(empty($_post['link']['name'])) { showmessage(l('sitename_noempey'), http_referer); } else { $_post['link']['name'] = safe_replace($_post['link']['name']); } if($_post['link']['logo']) { $_post['link']['logo'] = safe_replace($_post['link']['logo']); } $data = new_addslashes($_post['link']); $linkid = $this->db->insert($data, true); if( ! $linked) { return false; } $siteid = $this->get_siteid(); //更新附件状态 if(pc_base::load_config('system', 'attachment_stat') & $_post['link']['logo']) { $this->attachment_db = pc_base::load_model('attachment_model'); $this->attachment_db->api_update($_post['link']['logo'], 'link-' . $linkid, 1); } showmessage(l('operation_success'), http_referer, '', 'add'); } else { $show_validator = $show_scroll = $show_header = true; pc_base::load_sys_class('form', '', 0); $siteid = $this->get_siteid(); $types = $this->db2->get_types($siteid); include $this->admin_tpl('link_add'); } } /* 异步更新排序 */ /* 手动更新排序 */ /* 添加友情链接分类 */ /* 删除分类 */ /* 分类管理 */ /** * 修改友情链接分类 */ public function edit_type() { if(isset($_post['dosubmit'])) { $typeid = intval($_get['typeid']); if($typeid return false; if( ! is_array($_post['type']) || empty($_post['type'])) return false; if((!$_post['type']['name']) || empty($_post['type']['name'])) return false; $this->db2->update($_post['type'], array('typeid'=>$typeid)); showmessage(l('operation_success'),'?m=link&c=link&a=list_type','', 'edit'); } else { $show_validator = $show_scroll = $show_header = true; //查询分类内容 $info = $this->db2->get_one(array('typeid'=>$_get['typeid'])); if( ! $info) { showmessage(l('linktype_exit')); extract($info); include $this->admin_tpl('link_type_edit'); } } } /** * 删除友情链接 */ public function delete() { if( ! isset($_get['linkid']) || (empty($_get['linkid']) && ! isset($_post['linkid'])) || empty($_post['linkid'])) { showmessage(l('illegal_parameters'), http_referer); } else { if(is_array($_post['linkid'])) { foreach($_post['linkid'] as $linkid_arr) { //批量删除友情链接 $this->db->delete(array('linkid'=>$linkid_arr)); //更新附件状态 if(pc_base::load_config('system', 'attachment_stat')) { $this->attachment_db = pc_base::load_model('attachment_model'); $this->attachment_db->api_delete('link - '. $linkid_arr); } } showmessage(l('operation_success', '?m=link&c=link')); } else { $linkid = intval($_get['linkid']);  if($linkid ) { return false; } //删除友情链接 $result = $this->db->delete(array('linkid'=>$linkid)); //更新附件状态if(pc_base::load_config('system','attachment_stat')) { $this->attachment_db = pc_base::load_model('attachment_model'); $this->attachment_db->api_delete('link-'.$linkid); } if($result){ showmessage(l('operation_success'),'?m=link&c=link'); }else { showmessage(l(operation_failure),'?m=link&c=link'); } } showmessage(l('operation_success'), http_referer); } } }/** * 几点注意: * 1. 作为一款产品,你可以感受到它程序的严谨性,照着做。 * 2. 操作数据类和其它系统类均在 libs/classes/ 中,数据模型基类model.class.php通过数据库工厂类作为抽象层调用操作数据库的方法。 * 3. 查询所有为listinfo, 单条信息为get_one, 增加为insert, 修改为update。 * 4. 提示消息为系统公共函数showmessage(),在 libs/functions/global.func.php 中。 * 5. l()方法为语言处理函数,将读入语言包,根据后台配置显示英文/中文, 同样是系统公共函数,
* 6. 加载后台模板 include $this->admin_tpl(); 这是admin模块下admin.class.php类的方法
* */
5. 建立后台模板文件
后台模板文件都在 modules/link/templates 下,文件名统一以“ .tpl.php”结尾
/** * 后台模板局部 */phpdefined('in_admin') or exit('no permission resources.');$show_dialog = 1;include $this->admin_tpl('header', 'admin');?>
class=search-form> class=explain-col> :      默认分类 php if(is_array($type_arr)){ foreach($type_arr as $typeid => $type){ ?>
/** * 几点注意: * 1. 后台模板是混编风格,由于在后台控制器中总是最后调用模板,所以系统库和函数以及变量总是可用的。 * 2. 模板底部可以写一些自己的js操作函数。 */phpcms的模块化设计非常人性化,更多有趣的地方等待大伙儿去发现,等待:[pc]phpcms二次开发指南(下)
link:http://www.cnblogs.com/farwish/p/4249318.html
@黑眼诗人 
以上就介绍了[pc]phpcms二次开发指南(上),包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product