[PC] PHPCMS secondary development guide (I), phpcms secondary development _ PHP Tutorial

Source: Internet
Author: User
[PC] PHPCMS secondary development guide (I), phpcms secondary development. [PC] PHPCMS secondary development guide (I), phpcms secondary development ------------------------------------------------------------------------------------- PHPCMS has excellent functions, since [PC] PHPCMS secondary development guide (I), phpcms secondary development guide

Bytes -------------------------------------------------------------------------------------

PHPCMS has complete functions, and its built-in modules are not available. the loose coupling feature makes it very suitable for secondary development of enterprises.

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

1. all modules of the PC are located in the module directory, which is the same as the data table name;

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

Front-end controllers such as index. php do not need to inherit any classes for front-end operations;

The background controller generally needs to inherit the admin class of the admin module. Once the admin class is inherited, permission verification is required (or not ).

II. summarize the steps of the development background module:

1. backend access extended modules:

Extension-menu management-add menu-superior: as a level-1 menu (module name, file name, method name)

Add sub-menu-superior: a level-1 menu (fill in a module name that does not exist, fill in a file name that does not exist, fill in a method name that does not exist)

After the extension module, you need to register the module in v9_module! (Equivalent to installation)

  

2. create a data table:

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

  

3. create a background data model

 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 ();}} /*** Notes: * 1. the data model of PC is basically a weakness, but it only specifies the database settings and the corresponding table name. if it is not a thorough MVC, simply copy and modify it. * 2. this model is generally called in the controller constructor method.
*/

4. create a background controller:

 M = new_html_special_chars (getcache ('link', 'commons'); $ this-> db = pc_base: load_model ('link _ Model '); $ this-> db2 = pc_base: load_model ('Type _ Model');}/*** link list */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 ['na Me '];} $ 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.doc ument. 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 ');} /* verify that the category name already exists when the title is duplicated and verified *//*** Add link */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 (); // update the attachment status 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 = $ s How_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 ');}} /* asynchronously update the sorting */* manually update the sorting */* Add a link category */* delete a category */* manage a category * // modify the category link category */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; // query the category content $ info = $ this-> db2-> get_one (array ('typeid' = >$ _ GET ['typeid']); if (! $ Info) {showmessage (L ('linktype _ exit '); extract ($ info); include $ this-> admin_tpl ('link _ type_edit ');}}} /*** delete link */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) {// batch delete links $ this-> db-> delete (array ('linkid' => $ linkid_arr); // update the attachment status if (pc_base :: load_config ('system', 'attachment _ stat') {$ this-> attachment_db = pc_base: load_model ('attachment _ Model'); $ this-> attachment_d B-> api_delete ('Link-'. $ linkid_arr) ;}} showmessage (L ('Operation _ success ','? M = link & c = link');} else {$ linkid = intval ($ _ GET ['linkid']); if ($ linkid <1) {return false;} // delete the link $ result = $ this-> db-> delete (array ('linkid' => $ linkid )); // update the attachment status 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) ;}}/ *** Notes: * 1. as a product, you can feel the rigor of its program. * 2. the Operation Data class and other system classes are in libs/classes/. The data model base class model. class. php calls the database operation method through the database factory class as the abstract layer. * 3. all listinfo information is queried. the single message is get_one, added as insert, and changed to update. * 4. the prompt message is the system public function showmessage (), which is in libs/functions/global. func. php. * 5. L () is a language processing function. it will be read into the language pack and displayed in English/Chinese based on background configurations. it is also a public function of the system,
* 6. load the background Template include $ this-> admin_tpl (""); this is the admin. class. php class method under the admin module.
* */

5. create a background template file

The background template files are all in modules/link/templates, and the file names end with ". tpl. php ".

/*** Background template partial */
 Admin_tpl ('header', 'admin');?>
 
 

: Default category $ Type) {?> $ Typeid;?> ">

/*** Note: * 1. the background template is a mixed editing style. because the template is always called at the end of the background controller, the system Library, functions, and variables are always available. * 2. you can write some JS operation functions at the bottom of the template. */

The modular design of PHPCMS is very user-friendly. more interesting places are waiting for everyone to find out. waiting: [PC] PHPCMS secondary development guide (below)

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

@ Blackeye poet

NLP (I), phpcms secondary development of ------------------------------------------------------------------------------------- PHPCMS itself function has been very complete, from...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.