Php notes: PHPcms module development introduction _ PHP Tutorial

Source: Internet
Author: User
Php notes: A Preliminary Study on PHPcms module development. Due to the working relationship, you can only temporarily stop studying mongodb. start to study PHPcms. so far, I have basically completed module development. here is a summary over the weekend. I found that due to the working relationship, php can only temporarily abandon its research on mongodb. start to study PHPcms.

So far, I have basically completed the development of the module. I am here to make a summary over the weekend. I found that phpcms is well written, but there are not many documents.

Let's not talk nonsense. for the module development of phpcms, first we need to understand the directory structure of the module.

We can be in http://v9.help.phpcms.cn/html/2010/structure_0928/69.html

Find the directory structure and the stuff (that is, the module) we want to develop is under/phpcms/modules /.

If there is nothing special, before developing a module, we should first establish a directory according to the directory structure and design a database table structure. for example, we should create a module named my_test.

The directory structure in mytest is as follows:

Mytest

-- Class // This is the class used by the mytest module.

-- Function // functions used by the mytest module

-- Install // install some configuration files required by this module and create myslq statements for data tables.

-- Language // used in multiple languages

-- Config. ini. php // This configuration file is used to describe some information about the entire module.

-- Extention. inc. php // This is used to create a directory structure. This file is also used to control permissions.

-- Model. php // which data models are used by the module (which tables are used .)

-- Model. SQL // records of the model inserted into the database

-- My_test. SQL // This file will be executed during installation, and the SQL statement for creating a database table will be put in

-- Templates //, template file used by the mytest module

-- Uninstall // The configurations and files used to uninstall the module

I have not studied the files in this file.

My_test.php // This is the background controller file of the mytest module'

Index. php // This is the front-end controller. I have nothing to write about.

After creating such a structure, we also need to create our data model under/phpcms/model /.

For example, my_test_model.class.php (this uses a typical factory mode)

What is written in each file? let's look at it one by one. First, let's look at the file we wrote under the model folder.

The code is as follows:


Defined ('in _ PHPCMS ') or exit ('no permission resources .');
Pc_base: load_sys_class ('model', '', 0 );
Class my_test_model extends model {
Public function _ construct (){
$ This-> db_config = pc_base: load_config ('database ');
$ This-> db_setting = 'default'; // default database configuration. // you can select multiple databases here.
$ This-> table_name = 'My _ test'; // this is the table name. no table prefix is required.
Parent: :__ construct ();
}
}
?>


The role of the first line is to determine whether it is in the phpcms runtime framework.

The second line loads the model class of the system. the following parameter 0 indicates that it is not instantiated.

The last line calls the constructor of the parent class. it can be found in phpcms/libs/classes/model. class. php.

This model class defines many basic addition, deletion, modification, and query operations on data. I will discuss in detail some basic methods of the model later.

Next let's take a look at the stuff in modules.

The first language is used to support multi-language menus.

Then config. ini. php, which contains information about the module installation.

This structure is in the file.

The code is as follows:


$ Module = 'mytest'; // model used
$ Modulename = 'here is the module name ';
$ Introduce = 'Module description information ';
$ Author = 'author ';
$ Authorsite = 'author website ';
$ Authoremail = 'author email ';


The content is clearly marked.

Next, the extention. inc. php file is used to create the directory structure of the background management menu and to control permissions.

The code is as follows:


$ Id = $ menu_db-> insert (array ('name' => 'Operation name', 'parentid' => parent ID, 'M' => 'Module ', 'C' => 'controller', 'a' => 'action', 'data' => '', 'storder' => sort, 'display' => ''), true); // The last true value is used to return the ID


The file should end with an array, which is used to insert the system's \ language \ zh-cn \ system_menu.lang.php file in the format below

The code is as follows:


$ Language = array (
'Here is the name of your operation '=> 'here is the Chinese translation of the operation ',
Similar to: 'mytest _ init' => 'Display list'
);


Then there is model. php. this is what data models you use, which tables can be understood as used.

The code is as follows:


Return array ('mytest', 'My _ test_artcle ');


Then there is model. SQL, which is used to insert data into the system model table.

The code is as follows:


Insert into 'phpcms _ Module' ('module', 'name', 'URL', 'iscore', 'version', 'Description', 'setting', 'storder ', 'disabled ', 'installdate', 'updatedate') VALUES ();


Then the mytest. SQL statement used to create your database table should be written in this file.

Then, the template you are using should be placed in the templates. the naming rule should be mytest_add.tpl.php.

Finally, you have made some research on your controller. in the controller, the action passed to each url is a =? The default action is init.

The code is as follows:


Defined ('in _ PHPCMS ') or exit ('no permission resources .');
Pc_base: load_app_class ('admin', 'admin', 0 );
Class mytest extends admin (){
Public function _ construct (){
Parent: :__ construct; // call the constructor of the parent class.
}
Public function init (){
Echo "here is the default operation method ";
}
Public function add (){
Include $ this-> admin_tpl ('mytest _ add'); // use the Template method.
}
}


After writing all the above files in the controller, we can install our module.

Sorry. I started to study PHPcms. so far I have basically completed the development of the module. let's make a summary here over the weekend. I found that 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.