[PC] PHPCMS Two development Guide (above), phpcms two development _php tutorials

Source: Internet
Author: User
Tags db2

[PC] PHPCMS Two development Guide (above), phpcms two times development


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

The phpcms itself is already well-developed, and its own modules can be used, loosely coupled to make them ideal for two of business development.

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

I. PC all modules are in the module directory, with the same name as the data table;

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

Front controller such as index.php need not inherit any class, for foreground operation;

Background controller is generally required to inherit the admin module of the admin class, once inherited admin requires permission authentication (also can not inherit).

Two. Summarize the steps for developing the backend module:

1. Background access to the extended module:

Extended-Menu Management-Add menu-ancestor: As a menu (module name, file name, method name)

Add submenu-Ancestor: A One-level menu (fill in the nonexistent module name, fill in the nonexistent file name, fill in the non-existent method name)

After expanding the module, you need to register the module in V9_module! (equivalent to installation)

  

2. Create a data table:

Create Table v9_link (     ...) engine=default CharSet='UTF8';

  

3. Create a data model behind the scenes

 
  Php
defined Exit (' No permiss resources. ') );p c_base:: Load_sys_class (' model ', ', 0); class extends Model { function __construct () { $this->db_config = pc_base:: Load_config (' database '); $htis->db_setting = ' default '; $this->table_name = ' link '; Parent::__construct (); } } /* * * NOTE: * 1. PC data model is basically chicken, just specify the database settings and the corresponding table name, non-exhaustive MVC, directly copy a modification can. * 2. This model is typically called in the controller construction method.
*/

4. Create a background controller:

 Php/** * Backstage links, complete curd*/    defined(' In_phpcms ') orExit(' No permission resources. ')); Pc_base:: Load_app_class (' admin ', ' admin ', 0); classLinkextendsAdmin {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-&GT;DB2 = Pc_base::load_model (' Type_model ')); }        /** * Links list*/         Public functioninit () {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-&GT;ADMIN_TPL (' Link_list '); }        /* Judging title repetition and verification*/                   /* When adding a category, verify that the classification name already exists*/        /** * Add links*/         Public functionAdd () {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 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=$show _header=true; Pc_base:: Load_sys_class (' form ', ' ', 0); $siteid=$this-Get_siteid (); $types=$this->db2->get_types ($siteid); include $this-&GT;ADMIN_TPL (' Link_add '); }            }         /*Asynchronous Update ordering*/         /*Manually update sort*/         /*Add link category*/         /*Delete Category*/         /*Classification Management*/         /** * Modify links category*/         Public functionEdit_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 category Content                $info=$this->db2->get_one (Array(' typeid ' =$_get[' typeID '])); if( !$info) {showmessage (L (' Linktype_exit ')); Extract($info); include $this-&GT;ADMIN_TPL (' Link_type_edit '); }            }        }         /** * Delete links*/         Public functionDelete () {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) {                        //Delete links in bulk                        $this->db->delete (Array(' LinkId ' =$linkid _arr)); //Update 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 _arr); }} showmessage (L (' Operation_success ', '? M=link&c=link ')); } Else {                    $linkid=intval($_get[' LinkId ']); if($linkid< 1) {                        return false; }            //Delete links            $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); }        }    }/** Note: * 1. As a product, you can feel the rigor of the program, do it. * 2. The Operation data class and other system classes are all in libs/classes/, and the data model base class model.class.php The method of invoking the operational database through the database factory class as an abstraction layer. * 3. Query all for Listinfo, single information for Get_one, add to insert, modify to update. * 4. The prompt message is the system common function showmessage (), in libs/functions/global.func.php. * 5. The L () method is a language processing function that reads the language pack, which is displayed in English/Chinese according to background configuration, and is also a common system function.
* 6. Loading a background template include $this->admin_tpl (""); This is the method of the Admin.class.php class under the admin module
* */

5. Create a background template file

Background template files are under Modules/link/templates, the file name is unified with ". Tpl.php" End

/** * Background template local*/
 Phpdefined(' In_admin ') orExit(' 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; Default Classification &nbsp; php if(is_array($type _arr)) { foreach($type _arr as $typeid = $type) { ?> $typeid;? > "> echo $type;? >&nbsp;
/** Note: * 1. Background templates are a mixed style, and the system libraries and functions and variables are always available because the template is always last called in the background controller. * 2. At the bottom of the template can write some of their own JS operation functions. */

PHPCMS's modular design is very human, more interesting places to wait for everyone to find, wait: [Pc]phpcms two development Guide (bottom)

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

@ Black-eyed poet

http://www.bkjia.com/PHPjc/947741.html www.bkjia.com true http://www.bkjia.com/PHPjc/947741.html techarticle [Pc]phpcms Two development Guide (above), phpcms two times development---------------------------------------------------------------------------- ---------Phpcms itself has been very well-developed since ...

  • 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.