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

Jul 21, 2016 pm 03:12 PM
mongodb php phpcms introduce relation Preliminary exploration right Work develop give up module of Research notes

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

How to configure MongoDB automatic expansion on Debian How to configure MongoDB automatic expansion on Debian Apr 02, 2025 am 07:36 AM

This article introduces how to configure MongoDB on Debian system to achieve automatic expansion. The main steps include setting up the MongoDB replica set and disk space monitoring. 1. MongoDB installation First, make sure that MongoDB is installed on the Debian system. Install using the following command: sudoaptupdatesudoaptinstall-ymongodb-org 2. Configuring MongoDB replica set MongoDB replica set ensures high availability and data redundancy, which is the basis for achieving automatic capacity expansion. Start MongoDB service: sudosystemctlstartmongodsudosys

What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? Apr 07, 2025 am 12:02 AM

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

Describe the purpose and usage of the ... (splat) operator in PHP function arguments and array unpacking. Describe the purpose and usage of the ... (splat) operator in PHP function arguments and array unpacking. Apr 06, 2025 am 12:07 AM

The... (splat) operator in PHP is used to unpack function parameters and arrays, improving code simplicity and efficiency. 1) Function parameter unpacking: Pass the array element as a parameter to the function. 2) Array unpacking: Unpack an array into another array or as a function parameter.

How can you prevent a class from being extended or a method from being overridden in PHP? (final keyword) How can you prevent a class from being extended or a method from being overridden in PHP? (final keyword) Apr 08, 2025 am 12:03 AM

In PHP, the final keyword is used to prevent classes from being inherited and methods being overwritten. 1) When marking the class as final, the class cannot be inherited. 2) When marking the method as final, the method cannot be rewritten by the subclass. Using final keywords ensures the stability and security of your code.

See all articles