PHPCMS Two-time development study

Source: Internet
Author: User

1, the new module is the phpcms/modules/directory under the new folder, the folder name is the module name.

2, the module is generally new three folders: Classes (module to use the class placed in this folder, through the Pc_base::load_app_classes () function loaded using)//

Functions (the function to be used by the module is placed in this folder, using the Pc_base::load_app_func () function to load)////

Template (module admin templates file, via $this->admin_tpl () method call)///

In addition, there are often install folders and uninstall folders. Specific reference to install the source package.

3, the realization mechanism of the module.

Controller: A PHP file within the module, which is a class file, the file name and the class name defined within the file must be consistent.

When we enter the Index.php?m= module name &c= controller name in the browser &c= the method name in the controller, first find the module folder, then find the controller, and then call the controller inside the method.

There are two kinds of methods in controller: (1) displaying some content, (2) processing the content of submission;

For the "show Something" method, first prepare some of the variables that you need to use in the template, and then use the Include template (",") to invoke the templates. The most important is the invocation of the template, the variables required in the template must be defined in the method within the controller.

Generally as follows:

     Public functionList_type () {$siteid=SITEID; $type _id=Trim(UrlDecode($_get[' type_id '])); $type _id=intval($type _id); if($type _id==""){             $type _id= ' 0 '; }           $setting= GetCache (' link ', ' Commons '); $SEO= SEO (SITEID, "', L (' link '),", "); includeTemplate (' link ', ' list_type ');//This sentence is a template call, the sentence above is basically to prepare for this sentence}

For "Processing submissions", the general structure is this:

     Public functionRegister () {$siteid=siteid;//Define the following required variablesif(isset($_post[' Dosubmit ']) {//If the submit button is pressed down, perform the following operation, typically insert the database and display the Insert success if($_post[' Name ']== "") {showmessage (L (' Sitename_noempty '), "? m=link&c=index&a=register&siteid=$siteid"); }             if($_post[' url ']== ' ") {showmessage (L (' Siteurl_not_empty '), "? m=link&c=index&a=register&siteid=$siteid"); }             if(!In_array($_post[' Linktype '],Array(' 0 ', ' 1 '))){                 $_post[' linktype '] = ' 0 '; }             $link _db= Pc_base::Load_model (Link_model);//Load Data Model$_post[' Logo '] =new_html_special_chars ($_post[' Logo ']); $logo= Safe_replace (Strip_tags($_post[' Logo '])); $name= Safe_replace (Strip_tags($_post[' Name '])); $url= Safe_replace (Strip_tags($_post[' URL '])); if($_post[' linktype ']== ' 0 '){                 $sql=Array(' SiteID ' =$siteid, ' typeid ' =intval($_post[' typeid ']), ' linktype ' =intval($_post[' Linktype ']), ' name ' = =$name, ' url ' = =$url); }Else{                 $sql=Array(' SiteID ' =$siteid, ' typeid ' =intval($_post[' typeid ']), ' linktype ' =intval($_post[' Linktype ']), ' name ' = =$name, ' url ' = =$url, ' logo ' =$logo); }             $link _db->insert ($sql)///Perform data insert Operation ShowMessage (L (' Add_success '), "? m=link&c=index&siteid=$siteid");//Show Insert Success}Else{ //Otherwise display page, wait for input and submit $setting= GetCache (' link ', ' Commons '); $setting=$setting[$siteid]; if($setting[' is_post ']== ' 0 ') {showmessage (L (' Suspend_application '),http_referer); }             $this->type = Pc_base::load_model (' Type_model ')); $types=$this->type->get_types ($siteid);//get all the links under the site categoryPc_base::load_sys_class (' form ', ' ', 0); $SEO= SEO (SITEID, "', L (' application_links '),", "); includeTemplate (' link ', ' register '); }    } 

4, about the template

The template uses the label technology, such as the content module, to display the classification of the label as follows:

{pc:content action= "lists" catid= "" num= "8" order= "id DESC" page= ""}    

So, what if it's our own definition of a module? It should look like this:

{pc: module name action= "Action function" catid= "num=" 8 "order=" id DESC "page="}    

Module name not much to say, just the folder name we defined. So where does the action function come from? It is defined in "module name _tag.class.php" Under Module name/classes directory, similarly, the main class name in this class file should also be "module name _tag", which defines a method called "action function". This method receives a parameter data, which is an array parameter, the array's key name is the above action,catid,num,order,page and so on (these variable names can be defined by themselves), the value is "action function", 15, 8, and so on.

A typical format is as follows:

     Public functionType_lists ($data) {            if(!In_array($data[' Listorder '],Array(' desc ', ' ASC '))) {                    $data[' listorder '] = ' desc '; }             $sql=Array(' module ' =>route_m, ' siteid ' =$data[' SiteID ']); $r=$this->type_db->select ($sql, ‘*‘,$data[' Limit '], ' listorder '.$data[' Listorder ']); returnNew_html_special_chars ($r); }     

PHPCMS Two-time development study

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.