Secondary Development of phpcms

Source: Internet
Author: User
Tags pconnect
File directory structure root directory |-API interface file directory |-caches cache file directory |-configs system configuration file directory |-caches _ * system cache directory |-phpcms framework home directory |- languages framework language package directory |-libs framework main class library and main function library directory |-model framework database model directory |-modules framework Module Directory |-templates framework system template directory |-phpsso_server phpsso main directory | -statics system attachment package |-CSS system CSS package |-Images System Image package |-js system JS package |-uploadfile website attachment directory |-Admin. PHP Background Management Portal |-index. main portal of the PHP program |-crossdomain. XML flash cross-origin File Transfer |-robots. t XT search engine spider restriction configuration file |-favicon. the icon URL of the ICO system accesses phpcms. It is developed in the MVC design mode and accessed by modules and operations. It is deployed and accessed in a single portal mode, no matter whether you access any module or function, there is only one unified portal. Parameter Name Description location remarks M model/Module name in phpcms/modules the Module Directory name must be c controller name phpcms/modules/module /*. PHP file name must be a event name phpcms/modules/module /*. method Name Module Access Method in PHP file [Example]: http://yourdomain.com/index.php? M = content & C = index & A = show & id = 1 where M = content is the model/Module name in phpcms/modules/contentc = index where the Controller name is in phpcms/modules/ content/index. PHPA = show indicates that the method name is in phpcms/modules/content/index. in PHP, the show () method id = 1 is the same as the normal get transmission parameters. If we access your domain name, such. Therefore, the following URL results are the same: the system also supports URL routing, which can bring other URL access effects. Http://www.yourdomain.com/index.php? M = content & C = index & A = init system class library and function call 1. the system library is located under the phpcms/libs/classes directory of the system. The name of the function library is *. class. php2. the system function library is located under the phpcms/libs/functions directory of the system. The function library file name is *. func. PHP, where global. func. PHP is loaded by default in the framework, global. func. functions in PHP can be called directly using the system class library pc_base: load_sys_class ('class name', 'Extended address', 'initializing? '). Example: $ HTTP = pc_base :: load_sys_class ('http'); // instantiate the HTTP class pc_base: load_sys_class ('format', '', 0); // call the Form class, do not instantiate the operating system function library to call pc_base: load_sys_func ('function library name'); example: pc_ B ASE: load_sys_func ('mail'); call the module in the phpcms V9 framework of the mail function package module. Each directory in the phpcms/modules directory is called a module. M example in URL access: http://www.yourname.com/index.php? M = content then you are accessing the phpcms/modules/content module. If you create a module, you only need to create a folder in the phpcms/modules directory and put it into your controller class. The controller of the controller phpcms V9 is the class file of the module, located in the phpcms/modules/module/directory. The class name is the file name +. php. For example, if a controller named mytest is used, you can name it mytest. php. The Controller class inherits the function library of the system by default and can be used directly. The Class Name of the controller class must be the same as the controller file name. If you create a mytest. php under the test module, then we enter the URL in the browser: http://www.yourname.com/index.php? Below M = Test & C = mytest is the basic format of a controller class, which will be explained in the build module section <? Phpdefined ('in _ phpcms ') or exit ('no permission resources. '); Class mytest {function _ construct () {} public function Init () {echo 'hellp phpcms V9, my name is defalut action' ;}}?> If the Controller class you added inherits other classes, be careful not to use the same method name as the method name in the class. Otherwise, your method will overwrite the original one. The naming rules of phpcms. The following naming rules should be followed when phpcms is used for secondary development: class files need to use. class. PHP is a suffix (this refers to the phpcms system class library file and the class library file in the module, which is not required by a third party), such as HTTP. class. PHP. Function files must be suffixed with. func. php (not required by a third party), such as mail. func. php. The class name and file name are consistent. For example, the file name of the phpcmsapp class is phpcmsapp. Class. php. The data model must be in the form of "data table name _ model. Class. php". The class name and file name must be the same. The configuration file is configured in the caches/configs/directory. Configuration File call: Use the load_config method $ upload_url = pc_base: load_config ('configuration file', 'configuration key to be obtained ', 'default configuration. This value works when the configuration item fails to be retrieved. ',' force reload? '); example: Call the attachment path in System Configuration $ upload_url = pc_base: load_config ('system ', 'upload _ url'); secondary development skills 1. if you want to perform secondary development on an existing controller, we do not recommend that you directly modify the Kernel File to facilitate the upgrade. You can use "My _*. PHP "form for secondary development. For example, you need to perform secondary development on phpcms/mood/index. php. You can create "my_index.php" my_index.php "in the same directory as index. php. The Code is as follows <? Phpclass my_index extends index {function _ construct () {parent ::__ construct ();}//...... Your code}?> In this way, when you access the index controller through URL, the system will point to my_index.php by default and the method of the original file will be inherited and can be directly used. Database Configuration File Location: caches/configs/database. php we open this configuration file and add our database configuration information. The database configuration information is a two-dimensional array structure. The default value is default. You can configure multiple database links (such as extended_1) according to the default structure. <? Phpreturn array ('default' => array ('hostname' => 'localhost', 'database' => 'phpcms ', 'username' => 'admin ', 'Password' => 'admin', 'tablepre' => 'v9 _ ', 'charset' => 'gbk', 'type' => 'mysql ', 'debug' => true, 'pconnect '=> 0, 'autoconnect' => 0 ), /* Add */'Extended _ 1' => array ('hostname' => '10. 10.125.2 ', 'database' => 'phpcms', 'username' => 'admin', 'Password' => 'admin', 'tablepre' => 'V9 _ ', 'charset' => 'gbk', 'type' => 'mysql', 'debug' => true, 'pconnect' => 0, 'autoconnect '=> 0),);?> Modify the preceding configuration based on your database connection information. After the modification is completed, save the configuration file of the database. Route configuration route configuration file location: caches/configs/route. php we open this configuration file and add our route configuration information. The routing configuration information is a two-dimensional array structure. The default value is default. The content of the route configuration file is as follows: <? Phpreturn array ('default' => array ('M' => 'admin', 'c' => 'index', 'A' => 'init '), 'test .youname.com '=> array ('M' => 'test', 'c' => 'index', 'A' => 'init'),);?> Data is a two-dimensional array. You can set the default parameters of post and get. Post and get correspond to the hyper-global variables $ _ post and $ _ Get in PHP respectively. In the following example, you can use $ _ post ['catid'] in the program to obtain the value of the array in post under data. The parameter levels set in data are relatively low. If an external program submits a variable with the same name, it overwrites the value set in the configuration file. For example: <? Phpreturn array ('default' => array ('M' => 'phpcms ', 'c' => 'index', 'A' => 'init ', 'data' => array ('post' => array ('catid' => 1 ), 'get' => array ('tentid' => 1)?> If the external program post a variable catid = 2, the value you get from $ _ post in the program is 2, instead of 1 set in the configuration file. System Configuration File Location: caches/configs/system. for details about PhP, refer to the development process of the document comment building module to create a module for your phpcms. The general development process is as follows: 1. create a database and a data table. (skip this step without database operations.) 2. create a Module Directory 3. create a module controller class. 4. create a module class and a module function. (You do not need to create a module if it is just a simple one.) 5. create a template file. 6. run and debug. Create a module in the phpcms V9 framework, which is located in the phpcms/modules directory. Each directory is called a module. If you want to create a module, create a folder in the phpcms/modules directory and put it in your controller class. For example, if I want to develop a module named test, first create a folder in the phpcms/modules directory and name it test. The test folder usually has three folders: classes is the module class library package functions is the module function library package templates is the module template package. Here, the Controller template containing permission control is usually placed, that is, the background template. If your template has a separate foreground template, you need to create a directory for your modules under phpcms \ Templates \ default to place the foreground template "default" as your style package name, we use default by default. Here we create a folder named test under the default folder to store the template to create a module controller. In the creation module, we have created a module named "test, next, we will add two controller classes for this module. The Controller of phpcms V9 is the class file of the module, which is located under the phpcms/modules/module/directory. The class name is the file name +. php. For example, if a controller named mytest is used, you can name it mytest. php. The Controller class inherits the function library of the system by default and can be used directly. The Class Name of the controller class must be the same as the controller file name. Controller files can be in the following two forms: 1. mytest. php controller, browser (without permission Control) <? PHP/* defined ('in _ phpcms ') or exit ('no permission resources. '); Class mytest {function _ construct () {} public function Init () {$ myvar = 'Hello world! '; Echo $ myvar;} public function mylist () {$ myvar = 'Hello world! This is a example! '; Echo $ myvar ;}} */?> The URL access method for this controller has previously been introduced to the http://www.yourname.com/index.php? M = Test & C = mytesthttp: // www.yourname.com/index.php? M = Test & C = mytest & A = mylist if "A" is not entered, the init method 2 is called by default. the mytest_admin.php controller and the background management (including permission Control) background control controller need to load the admin class under the admin module and inherit the class. Note that the controller class you added inherits from other classes. Be careful not to use the same method name as the method name in the Controller class. Otherwise, the impact may occur, for details, see the methods in the admin class. <? Phpdefined ('in _ phpcms ') or exit ('no permission resources. '); pc_base: load_app_class ('admin', 'admin', 0); Class mytest_admin extends admin {public function _ construct () {} public function Init () {$ myvar = 'Oh, I am phpcmser '; echo $ myvar ;}}?> Adding a template to the Controller calls phpcms to completely separate the template from the program. Therefore, we need to load the template in our controller program to display it more friendly. 1. load the foreground template file of the foreground template in the phpcms \ Templates \ Default \ Module name directory. In this example, you can load the template in phpcms \ Templates \ Default \ test as follows: include template ('test', 'mytest', 'default'); where test is the module name, mytest is the Template Name under the template directory, and default is the style name, defalut is left blank by default. In the above example, if you want to give mytest. in PHP, The init method loads a mytest template. The following public function Init () {$ Var = 'Hello world! '; Include template ('test', 'mytest', 'default');} then the corresponding template is loaded when we access this method through URL. 2. the background template file is loaded in the phpcms \ modules \ Module name \ templates directory. In this example, the template Loading Method in phpcms \ modules \ test \ templates is as follows: include $ this-> admin_tpl ('mytest _ admin_list '); where mytest_admin_list is mytest_admin_list.tpl.php in phpcms \ modules \ test \ templates. Note: The background template must be. TPL. in the above example, if you want to load a mytest_admin_list template for the init method in mytest_admin.php, the following public function Init () {$ myvar = 'Oh, I am phpcmser '; include $ this-> admin_tpl ('mytest _ admin_list ');} Create a database model-type database model in the phpcms/model/directory. We recommend that you use the data table name + '_ model. class. PHP 'if I want to use a Database "test" in the created module, first create a database model file named 'test _ model. class. the php' content is as follows: <? Phpdefined ('in _ phpcms ') or exit ('no permission resources. '); pc_base: load_sys_class ('model', '', 0); Class test_model extends model {public function _ construct () {$ this-> db_config = pc_base :: load_config ('database'); $ this-> db_setting = 'default'; $ this-> table_name = 'test'; parent ::__ construct () ;}}?> Note: 1. the database model class name must be the same as the file name; 2. $ this-> db_setting = 'default' indicates the name of the database link pool configured in the database configuration file. The default value is default, which is not required in general. 3. $ this-> table_name = 'test' is the name of the data table, so we have created a database model class. In the module controller, use $ this-> DB = pc_base: load_model ('test _ model'); to load. The details are as follows <? PHP/* defined ('in _ phpcms ') or exit ('no permission resources. '); Class mytest {private $ db; function _ construct () {$ this-> DB = pc_base: load_model ('test _ model ');} public Function Init () {$ result = $ this-> DB-> select (); var_dump ($ result) ;}} */?> For the methods supported in $ this-> dB, see phpcms/libs/classes/model. Class. php.

 

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.