Due to the working relationship, we can only temporarily give up the research on MongoDB. began to study phpcms.
So far I have basically completed the development of the module. Take advantage of the weekend to come here and make a summary. I found Phpcms's writing is good, but the documentation is really not much.
Don't talk nonsense. For PHPCMS module development. First, you need to understand the directory structure of the module.
We could be in http://v9.help.phpcms.cn/html/2010/structure_0928/69.html.
Find his directory structure. The stuff we're going to develop (i.e. module) is under/phpcms/modules/.
If there's nothing special in developing a module, you have to build a directory structure and design a database table structure. Let's say we build a module called my module my_test
The following should be the directory structure under MyTest
MyTest
--class//This is the class that the MyTest module will use
Functions used by the--function//mytest module
--install//install some of the configuration files needed for this module and create a datasheet MYSLQ statement or something here
When you--language//multiple languages, you use them.
--config.ini.php//This configuration file is used to describe some of the information about the entire module
--extention.inc.php//This is to create the 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//the record of inserting the model into the database
--my_test.sql//This file is executed when it is installed, and the SQL that builds the database table is put in
Template files used by the--templates//,mytest module
--uninstall//uninstall modules used in the configuration and files
I didn't study the file inside.
my_test.php//This is the MyTest module's background controller file '
index.php//This is the controller of the front desk, this I did not write anything.
Once we've built one of these, we need to build our data model under/phpcms/model/.
For example my_test_model.class.php (this uses a very typical factory model)
Exactly what is written in each file. Let's look at one of them. First, let's look at the file we wrote under the Model folder.
Copy Code code 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 ';//defaults to the database configuration.//Multiple libraries You can choose a library here
$this->table_name = ' my_test '; This is the table name without a table prefix.
Parent::__construct ();
}
}
?>
The first line of action is to determine whether it is within the PHPCMS operating framework.
The second line loads the model class of the system, and the following argument 0 means that it is not instantiated.
The last line calls the constructor method of the parent class. Can be found in the phpcms/libs/classes/model.class.php
And this model class defines a lot of data on the operation of the most basic additions and deletions to check. Later, I will elaborate on the basic methods of model.
And then look at the stuff inside the modules.
Let's look down one at a while. The first language is used to support the multilingual menu.
Then there is the config.ini.php, which contains some information about the installation of the module.
This structure is inside the file.
Copy Code code as follows:
$module = ' mytest ';//Use model
$modulename = ' Here is the name of the module ';
$introduce = ' Description information of the module ';
$author = ' author ';
$authorsite = ' Author website ';
$authoremail = ' Author email ';
It's clearly marked.
And then it's extention.inc.php. This file is used to create the directory structure of the background Management menu and is used to control permissions
Copy Code code as follows:
$id = $menu _db->insert (the ' name ' => ' here says operation name ', ' ParentID ' => parent ID, ' m ' => ' module ', ' C ' => ' controller ', ' A ' => ' action ') , ' Data ' => ', ' listorder ' => sort, ' display ' => ' is displayed '), true;//The last true is used to return the ID
The file should end up with an array that is used to insert the system's \language\zh-cn\system_menu.lang.php inside the format below
Copy Code code as follows:
$language = Array (
' Here is the operation name ' => ' here is the operation of the Chinese translation ',
Similar to: ' Mytest_init ' => ' Display list '
);
And then it's model.php, which is what data models you use to understand which tables are used.
Copy Code code as follows:
Return Array (' mytest ', ' my_test_artcle ');
And then Model.sql, which is used to insert data into the system's model table.
Copy Code code as follows:
INSERT into ' phpcms_module ' (' module ', ' Name ', ' url ', ' iscore ', ' version ', ' Description ', ' Setting ', ' Listorder ', ' disabl Ed ', ' InstallDate ', ' updatedate ') VALUES ();
Then it's mytest.sql. The statement that builds your database table should be written in this file.
And then the template you're using should be in the templates named after the rules should be mytest_add.tpl.php
And finally, your controller, this is some research. Inside the controller is the action for each URL you pass over, that is, a=. The default action is init
Copy Code code 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;//call the constructor of the parent class
}
Public Function init () {
echo "Here is the default action method";
}
Public function Add () {
Include $this->admin_tpl (' Mytest_add ');//Use template method
}
}
The controller has written that we can install our module after we have finished writing the above files.