


PHP Notes: An initial introduction to PHPcms module development_PHP Tutorial
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.
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
$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
$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
$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
return array('mytest',' my_test_artcle');
Then model.sql This is used to insert data into the model table of the system
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
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.
