Table of Contents
phpcms V9 added module (reprinted), phpcmsv9
Home Backend Development PHP Tutorial phpcms V9 add module (transfer), phpcmsv9_PHP tutorial

phpcms V9 add module (transfer), phpcmsv9_PHP tutorial

Jul 12, 2016 am 08:49 AM
phpcms

phpcms V9 added module (reprinted), phpcmsv9

reprinted from: http://www.cnblogs.com/Braveliu/p/5101345.html

is The development process of creating a module in phpcms

【1】Create a module directory

Through the previous study, we already know that the modules in the phpcms V9 framework are located in the phcms/modules directory. Each directory is called It is a module.

If you want to create a module, just create a folder under the phpcms/modules directory and put your controller class in it.

For example, if I want to develop a module called test, then first create a folder in the phpcms/modules directory and name it test.

Observing the structure of other modules, we can see that the standard structure of the test module should usually be like this:

classes is the module class library package

functions is the module function library package

templates is the module template package, which usually contains controller templates containing permission control, that is, background templates.

If your template has a customized front-end template, you need to create a directory with your module name in the phpcmstemplatesdefault directory to place the front-end template. "default" is the name of your style package. We use default by default .

【2】Create module controller class

In the previous step, we have created a module named test. Next, we will continue to add two controller classes to this module.

The controller of phpcms V9 is the class file of the module, located under the phpcms/modules/module name/ directory. The name of the class file is the controller name .php. For example, if a controller is named mytest, then it can be named mytest.php. The controller class inherits the system's function library by default and can be used directly.

The class name of the controller class and the controller file name must be the same .

Controller class files include two forms:

1. Front-end browsing (excluding permission control), mytest.php controller

is in the phpcms/modules/test directory Next, create a new text file, name it mytest, change the file type to php, open it with Notepad and edit the content as:

phpcms V9 add module (transfer), phpcmsv9_PHP tutorial

 1 <?php
 2     defined('IN_PHPCMS') or exit('No permission resources.');
 3     class mytest 
 4     {
 5         function __construct(){}
 6         public function init() 
 7         {
 8             $myvar = 'hello world!';
 9             echo $myvar;
10         }
11         public function mylist() 
12         {
13             $myvar = 'hello world! This is an example!';
14             echo $myvar;
15         }
16     }
17 ?>
Copy after login

phpcms V9 add module (transfer), phpcmsv9_PHP tutorial

Actually, the URL access method of this controller has been introduced before, please refer to "phpcms V9 MVC Mode and URL Access Analysis"

http://www.abcd.com.cn/phpcms/index.php?m=test&c=mytest is equivalent to

http://www.abcd.com.cn/phpcms/index.php?m=test&c=mytest&a=init.

When the "a" value is not filled in, the init method is called by default.

Why is this like this? Please read "phpcms V9 MVC Mode and URL Access Analysis" again.

2. Backend management (including permission control), mytest_admin.php controller

The background controller needs to load the admin class under the admin module and inherit this class. It should be noted that because the added controller class inherits other classes, be careful that the method name of the controller class is not the same as the method name in the class, otherwise it will cause effects. Please check the methods in the admin class for details.

In the phpcms/modules/test directory, create a new text file, name it mytest_admin, change the file type to php, open it with Notepad and edit the content as:

phpcms V9 add module (transfer), phpcmsv9_PHP tutorial

 1 <?php
 2     defined('IN_PHPCMS') or exit('No permission resources.');
 3     pc_base::load_app_class('admin','admin',0);
 4     class mytest_admin extends admin 
 5     {
 6         public function __construct() {}
 7         public function init() 
 8         {
 9             $myvar = 'oh,i am phpcmser';
10             echo $myvar;
11         }
12     }
13 ?>
Copy after login

phpcms V9 add module (transfer), phpcmsv9_PHP tutorial

Add template call in controller

phpcms can achieve complete separation of templates and programs, so templates must be loaded in our controller program so that they can be displayed more friendly.

1. Load the frontend template

The front-end template file is in the directory with the phpcmstemplatesdefault module name. This example is also in phpcmstemplatesdefaulttest.

The method to load the template is as follows:

1 // 加载模板方法:
2 include template('test', 'mytest', 'default');
Copy after login

Among them, test is the module name, mytest is the template name in the template directory, default is the style name, and the default is default.

In the above example, if you want to load a mytest template for the init method in mytest.php (you can copy index.html under the content module as an alternative), as follows (so the template name is index):

1 public function init() 
2 {
3     $myvar = 'hello world!';
4     echo $myvar;
5     include template('test', 'index');
6 }
Copy after login

At this time, when we access the method through the URL, the corresponding template will be loaded.

2. Load background template

The background template file is in the templates directory of the phpcmsmodules module name. This example is also in phpcmsmodulestesttemplates

The method to load the template is as follows:

// 加载模板方法:
include $this->admin_tpl('mytest_admin_list');
Copy after login

Where mytest_admin_list is mytest_admin_list.tpl.php in phpcmsmodulestesttemplates.

Note: The template here must have .tpl.php as the suffix

In the above example, if you want to load a mytest_admin_list template to the init method in mytest_admin.php, as follows:

1 public function init() 
2 {
3     $myvar = 'oh,i am phpcmser';
4     echo $myvar;
5     include $this->admin_tpl('mytest_admin_list');
6 }
Copy after login

For loading the template part, you can also see the implementation of the system framework source code content module phpcmsmodulescontent content.php file.

【3】Create database model class

At this point, it is clear that the database model of each module is located in the phpcms/model/ directory.

数据模型文件的命名规则建议为:数据表名称 + '_model.class.php'

如果在我们的创建的模块中我要使用一个数据库“test”,首先需要建立一个数据库模型文件,文件名称为'test_model.class.php'

内容如下:

phpcms V9 add module (transfer), phpcmsv9_PHP tutorial

 1 <?php
 2 defined('IN_PHPCMS') or exit('No permission resources.');
 3 pc_base::load_sys_class('model', '', 0);
 4 class test_model extends model
 5 {
 6     public function __construct() 
 7     {
 8         $this->db_config = pc_base::load_config('database');
 9         $this->db_setting = 'default';
10         $this->table_name = 'test';
11         parent::__construct();
12     }
13  }
14 ?>
Copy after login

phpcms V9 add module (transfer), phpcmsv9_PHP tutorial

书写数据库模型类注意一下几点:

1. 数据库模型类名称必须与文件名称相同。

2. 必须继承与数据库模型基类model。

3. $this->db_setting = 'default'为数据库配置文件中配置数据库链接池名称,默认为default,一般情况下不需要修改。

4. $this->table_name = 'test'为数据表名称。

这样我们就建立好一个数据库模型类。那么,怎么使用呢?

在模块的控制器中使用(加载方式):

$this->db = pc_base::load_model('test_model');
Copy after login

具体如下:

phpcms V9 add module (transfer), phpcmsv9_PHP tutorial

 1 db->select(); // 调用select方法
16             var_dump($result);
17         }
18         public function mylist()
19         {
20             $myvar = 'hello world! This is an example!';
21             echo $myvar;
22         }
23     }
24 ?>
Copy after login

phpcms V9 add module (transfer), phpcmsv9_PHP tutorial

其中$this->db中所支持的方法请参照父类 phpcms/libs/classes/model.class.php 中方法。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1137573.htmlTechArticlephpcms V9 添加模块(转),phpcmsv9 转自:http://www.cnblogs.com/Braveliu/p/5101345.html 为phpcms创建一个模块的开发流程 【1】创建模块目录 通过前面的学...
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)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
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)

How to jump to the details page in phpcms How to jump to the details page in phpcms Jul 27, 2023 pm 05:23 PM

How to jump to the details page in phpcms: 1. Use the header function to generate a jump link; 2. Loop through the content list; 3. Get the title and details page link of the content; 4. Generate a jump link.

What framework is phpcms? What framework is phpcms? Apr 20, 2024 pm 10:51 PM

PHP CMS is a PHP-based open source content management system for managing website content. Its features include ease of use, powerful functionality, scalability, high security, and free open source. It can save time, improve website quality, enhance collaboration and reduce development costs, and is widely used in various websites such as news websites, blogs, corporate websites, e-commerce websites and community forums.

WeChat Login Integration Guide: PHPCMS Practical Combat WeChat Login Integration Guide: PHPCMS Practical Combat Mar 29, 2024 am 09:18 AM

Title: WeChat Login Integration Guide: PHPCMS in Action In today’s Internet era, social login has become one of the essential functions of a website. As one of the most popular social platforms in China, WeChat’s login function is also used by more and more websites. This article will introduce how to integrate the WeChat login function in the PHPCMS website and provide specific code examples. Step 1: Register a WeChat Open Platform Account First, we need to register a developer account on the WeChat Open Platform and apply for the corresponding development permissions. Log in [WeChat open platform]

Isn't phpcms free? Isn't phpcms free? Mar 01, 2023 am 10:24 AM

phpcms is not completely free. phpcms is an open source cms system, but open source does not mean free. It has two versions: free version and commercial version. The free version is limited to personal non-commercial use, while the commercial version requires purchasing a license; individuals can use it for research, and if it is commercial application , you need to pay a certain fee.

What does phpcms mean? What does phpcms mean? Apr 20, 2024 pm 10:39 PM

PHPCMS is a free and open source content management system (CMS) that features: open source, modularity, flexibility, user-friendliness and community support. It can be used to create various types of websites, including corporate websites, e-commerce websites, blogs, and community forums. Technical requirements include: PHP 5.6 or higher, MySQL, MariaDB or PostgreSQL database, and Apache or Nginx web server.

What versions of phpcms are there? What versions of phpcms are there? Jun 14, 2023 pm 01:13 PM

There are two well-known versions of phpcms, namely: 1. phpCMS4, which supports custom URL rules. The website management background is beautiful and easy to use, and has many front-end plug-ins, which can freely expand functions; 2. phpCMS2008R1, which supports multi-language, multi-site management, and page The manager is convenient, flexible, very lightweight, and runs fast.

What database does phpcms use? What database does phpcms use? Feb 21, 2023 pm 06:57 PM

phpcms uses mysql database. phpcms is a PHP open source website management system, developed using PHP+MYSQL as the technical basis. PHPCMS V9 adopts OOP method to build the basic operating framework. The supported PHP version is PHP5 and above, and the supported MYSQL version is MySql 4.1 and above.

PHPCMS username security setting strategy revealed PHPCMS username security setting strategy revealed Mar 14, 2024 pm 12:06 PM

PHPCMS user name security setting strategy revealed In website development, user account security has always been an aspect that developers attach great importance to. The security settings of the username are also crucial, because the username is not only the user's login credentials, but may also expose the user's personal information and even cause security risks. This article will reveal the username security setting strategy in PHPCMS and give specific code examples for developers to refer to. 1. Prevent common usernames. In order to improve the security of usernames, developers should prevent users from using excessive

See all articles