Home >Backend Development >PHP Tutorial >A preliminary introduction to PHPcms module development_PHP tutorial
Due to work, I can only give up the research on mongodb temporarily and start researching PHPcms.
So far I have basically completed the development of the module. I will come here to make a summary during the weekend. I found that phpcms is pretty good, but there are really not many documents.
No more nonsense. For phpcms module development, you must first understand the directory structure of the module.
We can download it at http://v9.help.phpcms.cn/html/2010/structure_0928/69.html
Find its directory structure. The stuff we want to develop (that is, the module) is under /phpcms/modules/
If there is nothing special, before developing a module, you must first establish the relevant directories according to the directory structure and design the database table structure. For example, we create a module called my module my_test
The following should be the directory structure under mytest
mytest
--class //This is the class used by the mytest module
--function//Function used by mytest module
--install//Some configuration files needed to install this module and create data table myslq statements are here
--language//Will be used when using multiple languages
--config.ini.php//This configuration file is used to describe some information of the entire module
--extension.inc.php//This is to create a directory structure. This file is also used to control permissions
--model.php//What data models are used by the module. (It can be understood as which tables are used.)
--model.sql//This is the record of inserting the model into the database
--my_test.sql//This file will be executed during installation, put the sql to create the database table
--templates //, template files used by the mytest module
--uninstall //Configuration and files used when uninstalling the module
I didn’t study the files in this. I will study them later and make up for them.
my_test.php //This is the background controller file of the mytest module`
index.php//This is the front-end controller, I didn’t write anything on this.
After establishing such a structure, we still need to establish our data model under /phpcms/model/
For example, my_test_model.class.php (this uses a very typical factory pattern)
Exactly 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:
The function of the first line is to determine whether it is within the running framework of phpcms.
The second line loads the model class of the system, and the following parameter 0 means 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
And this model class defines a lot of data operation methods, the most basic addition, deletion, modification and query. I will talk about some basic methods of model in detail later.
Let’s take a look at the stuff inside modules
Let’s look at the following one by one. The first language is used to support multi-language menus.
Then there is config.ini.php, which contains some information about module installation.
The file has this structure
The code is as follows:
It’s clearly marked inside
Then there is extension.inc.php. This file is used to create the directory structure of the background management menu and is also used to control permissions
The code is as follows:
There should be an array at the end of the file. This array is used to insert into the system's languagezh-cnsystem_menu.lang.php. The format is as follows
Then there is model.php. This is which data models you use. It can be understood as which tables are used
Then there is model.sql, which is used to insert data into the model table of the system
Then mytest.sql. The statements to create your database table should be written in this file
Then the template you use should be placed in templates. The naming rule should be mytest_add.tpl.php
Finally, there is your controller. This has been researched. The controller contains the action passed for each URL, which is the action of a=?. The default action is init
The code is as follows:
It's written in the controller. After we finish writing the above files, we can install our module.