[PC]PHPCMS Secondary Development Guide (Part 1)

WBOY
Release: 2016-08-08 09:30:35
Original
1381 people have browsed it

------------------------------------------------- ----------------------------------

PHPCMS itself has very complete functions. The built-in modules can be used or not. The loose coupling feature makes it very suitable for secondary development of enterprises.

The default route of PC is defined in phpcms/caches/configs/route.php, which is the init method of the index controller under the content module

1. All PC modules are in the module directory and have the same name as the data sheet;

 The file in the module directory is the controller, and the controller name is the same as the file name;

 Foreground controllers such as index.php do not need to inherit any class and are used for front-end operations;

 The background controller generally needs to inherit the admin class of the admin module. Once it inherits the admin, it requires permission verification (or it may not be inherited).

2. Summarize the steps to develop the backend module:

 1. Backend access extended module:

  Extension - Menu Management - Add Menu - Superior: as a first-level menu (module name, file name, method name)

                               ifier: a certain first-level menu (fill in the module name that does not exist, fill in the name of the file that does not exist, fill in the name of the method that does not exist)

  After extending the module, you need to register the module in v9_module! (equivalent to installation)

 2. Create data table:

create table v9_link( ......... )engine=myisam default charset='utf8';
Copy after login

 3. Establish the backend data model

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. 此模型一般在控制器构造方法调用。
*/
Copy after login

 4. Create a background controller:

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 < 1) 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 < 1) { 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类的方法
*
*/
Copy after login

 5. Create background template file

 Backend template files are all under modules/link/templates, and the file names end with “.tpl.php”

/** * 后台模板局部 */ php defined('IN_ADMIN') or exit('No Permission resources.'); $show_dialog = 1; include $this->admin_tpl('header', 'admin'); ?> class="search-form"> 
class="explain-col"> echo L('all_linktype')?>: echo L('all')?> &nbsp; 默认分类&nbsp; php if(is_array($type_arr)){ foreach($type_arr as $typeid => $type){ ?>echo $type;?>&nbsp;
/** * 几点注意: * 1. 后台模板是混编风格,由于在后台控制器中总是最后调用模板,所以系统库和函数以及变量总是可用的。 * 2. 模板底部可以写一些自己的JS操作函数。 */
Copy after login

The modular design of PHPCMS is very user-friendly. More interesting places are waiting for everyone to discover. Waiting for: [PC] PHPCMS Secondary Development Guide (Part 2)

Link: http://www.cnblogs.com/farwish/p/4249318.html

@黑eyedpoet 

The above introduces the [PC] PHPCMS Secondary Development Guide (Part 1), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!