Recently in the study of PHP, learning for a while to feel like to write something, but do not know what to write, the final goal of the PHPCMS plug-in, from the Internet to find a bit, most of the tutorials are just how to write the specific code plug-ins, and did not teach how to plug into the installation package, especially the official, no mention! Here to despise a little ~ OK below to write down some of the things I know, hoping to help the novice ~
Let's take a look at the specific structure of the plug-in package
MyTest
--class//This is the class that the MyTest module will use
Functions used by the--function//mytest module
--install//install this module requires some configuration files and build data table MYSLQ statement What's going on here?
--language//will be used when it comes to multiple languages.
--config.ini.php//This configuration file is used to describe the entire module of information
--extention.inc.php//This is to create a directory structure. This file is also used to control permissions
What data models are used by the--model.php//module. (You can understand which tables are used.)
--model.sql//this record of inserting a model into the database
--my_test.sql//This file will be executed at the time of installation, and the SQL that created the database table is put in
--templates template files used by//,mytest modules
--uninstall//The configuration and files used to unload the module
I did not study this document in the back of the study to fill up.
my_test.php//This is the MyTest module's background controller file '
index.php//This is the front desk controller, this I did not write anything.
Well, the plug-in package is basically the way it is-then the next step is to explain:
Once we've built a structure like this, we need to build our data model under/phpcms/model/.
For example my_test_model.class.php (this uses a very typical factory model)
What is written in each file. Let's look at it one by one. First look at the file we wrote under the Model folder.
The code is as follows:
<?php
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.//Multiple libraries You can choose a library here
$this->table_name = ' my_test ';//This is the table name without adding a table prefix
Parent::__construct ();
}
}
?>
The function of the first line is to determine whether it is within the PHPCMS operating framework.
The second line loads the system's model class, and the following parameter 0 means that it is not instantiated.
The last line invokes the construction method of the parent class. Can be found in phpcms/libs/classes/model.class.php
And this model class inside defines a lot of data operation methods of the most basic deletion and modification. I'll talk more about model basic methods in the future.
Then look at the modules inside.
Let's look down to the first language to support multi-lingual menus.
Then there is config.ini.php, which is written about the installation of the module.
This is the structure inside the file.
The code is as follows:
$module = ' mytest ';//model used
$modulename = ' This is the name of the module ';
$introduce = ' Description information of the module ';
$author = ' author ';
$authorsite = ' Author website ';
$authoremail = ' Author email ';
It's clearly marked in there.
And then extention.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:
$id = $menu _db->insert (Array (' name ' = ' = ' name ', ' parentid ' = ' parent id ', ' m ' = ' = ' module ', ' C ' + = ' controller ', ' a ' = ' = ' action ') , ' data ' = ', ' listorder ' = ' = ', ' Display ' = ' show '), true);//The last true is used to return the ID of the
The file should eventually have an array that is used to insert the system's languagezh-cnsystem_menu.lang.php inside the format as follows
$language = Array (
' Here is your operation name ' = ' and ' Here is the operation of the Chinese translation ',
Similar to: ' Mytest_init ' = ' Show list '
);
Here I explain separately:
$id: This is your plugin's menu ID number, mainly with the sub-menu (if any) is used to mount, is subordinate to it under the menu will be linked to the ID variable below it;
$menu _db->insert (): This is a method provided by PHPCMS, specifically in the integrated system Modul can be self-checking, which is to insert data into the database, the parameters are: array (what to insert), Boolean variable (return ID number), Boolean variable (whether to add data using replace into);
The variables of the array are also explained separately:
Name: It says the operation names
ParentID: This variable is the ID of the parent, that is, where you want the menu to appear,
M: module, that is, the module you want to call the following Controller C and action A are all the same without explanation,
Data: This should be the additional information, specifically how to use temporarily do not know,
Listorder: Sorting, mainly used when the menu is more often used to determine the order of the discharge position,
Display: That is to let the menu show, with 1 and 0, 1 represents the display, 0 means do not show do not use the example of the method Ah!
The last thing to say is parentid this variable, does it not decide where to put the menu? How do you know that? Look at the picture:
1-position "ParentID" =>0
2-position "ParentID" =>29
So you can put the menu in the desired position ~
And then there's model.php. This is what data models you use to understand which tables are used
The code is as follows: Return array (' mytest ', ' my_test_artcle '); And then there's model.sql. This is the code used to insert data into the system's model table as follows:
INSERT into ' phpcms_module ' (' module ', ' Name ', ' url ', ' iscore ', ' version ', ' Description ', ' Setting ', ' Listorder ', ' disabl ' Ed ', ' InstallDate ', ' updatedate ') VALUES ();
And then the statement that Mytest.sql set up your database table should be written in this file.
And then the template you're using should be named in the templates, and the rules should be mytest_add.tpl.php.
And finally, there's your controller. The controller is the action that you pass through each URL that is a=. The default action is init
The code is as follows:
<?php
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;//calling the constructor of the parent class
}
Public Function init () {
echo "Here is the default method of operation";
}
Public function Add () {
Include $this->admin_tpl (' Mytest_add ');//Methods for using templates
}
}
PHPCMS Plug-in