Home > Backend Development > PHP Tutorial > PHP Notes: An initial introduction to PHPcms module development_PHP Tutorial

PHP Notes: An initial introduction to PHPcms module development_PHP Tutorial

WBOY
Release: 2016-07-21 15:12:12
Original
845 people have browsed it

Due to work, I can only give up the research on mongodb temporarily. 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 inserts the model record 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)

Specifically 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.

Copy code 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.//If you have multiple libraries, you can choose the library here
                                                                                                                                                              db_setting =                                                 db_setting = ' Prefix
parent::__construct();
}
}
?>

The first line is used 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 contains this structure

Copy the code The code is as follows:

$module = 'mytest';// Model used
$modulename = 'Here is the name of the module';
$introduce = 'Module description information';
$author = 'Author';
$authorsite = 'Author website' ;
$authoremail = 'author email';

It is clearly marked

Then comes extension.inc.php. This file is used to create the directory structure of the background management menu and is also used to control permissions

Copy code The code is as follows:

$id= $menu_db->insert(array('name'=>'The operation name is written here', 'parentid'=>Parent ID, 'm'=>'Module' , 'c'=>'Controller', 'a'=>'Action', 'data'=>'', 'listorder'=>Sort, 'display'=>'Whether to display') , true);//The last true is used to return the ID

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
Copy code The code is as follows:

$language = array(
'Here is the operation name you gave'= >'Here is the Chinese translation of the operation',
Similar: 'mytest_init'=>'Display list'
);

Then model.php This is what you use Which data models can be understood as which tables are used
Copy code The code is as follows:

return array('mytest',' my_test_artcle');

Then model.sql This is used to insert data into the model table of the system
Copy code The code is as follows:

INSERT INTO `phpcms_module` (`module`, `name`, `url`, `iscore`, `version`, `description`, `setting`, `listorder `, `disabled`, `installdate`, `updatedate`) VALUES ();

Then mytest.sql. The statement 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

The last thing is your controller. This has been researched a lot. The action in the controller is the action passed by each URL, which is the action of a=?. The default action is init

Copy code 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');//How to use templates
 }
}

The controller is written. After we finish writing the above files, we can install our module.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326762.htmlTechArticleDue to work, I can only give up the research on mongodb temporarily. I started researching PHPcms. So far I have basically completed it. The development of the module. I came here to make a summary during the weekend. I found php...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template