search
HomeBackend DevelopmentPHP TutorialPHPCMS secondary development tutorial (transfer), phpcms secondary development tutorial_PHP tutorial

PHPCMS secondary development tutorial (reprinted), phpcms secondary development tutorial

Reprinted from: http://www.cnblogs.com/semcoding/p/3347600. html

PHPCMS V9 structural design

root directory
|–api structure file directory
|–caches cache file directory
| – configs system configuration file directory
|– caches_* system cache directory
|–phpcms phpcms framework main directory
|– languages ​​framework language package directory
|– libs framework main class library, main function library Directory
|– model framework database model directory
|– modules framework module directory
|– templates framework system template directory
|–phpsso_server phpsso main directory
|–statics system attachment package
| – css system css package
| – images system picture package
| – js system js package
|–index.php Program main entrance

PHPCMS V9 core file description

Modules and Controllers

Modules:

Modules in the phpcms v9 framework are located in the phpcms/modules directory. Each directory is called a module. That is the m in url access.

Example of accessing content module: http://www.yourname.com/index.php?m=content

Controller:

The controller of phpcms v9 is the class file of the module, located under the phpcms/modules/modules/ directory. The class name is the file name .php. For example, if a controller is named abc, then its name is abc.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. If you created an abc.php under the test module, then we enter the URL in the browser: http://www.yourname.com/index.php?m=test&c=abc

Secondary development skills

If you want to carry out secondary development on an existing controller, it is not recommended to directly modify the kernel file to facilitate the upgrade. You can use the form of "MY_*.php" Carry out secondary development.

For example, you want to perform secondary development on phpcms/mood/index.php. You can create "MY_index.php"

<?php
	class MY_index extends index{
		function __construct() {
			parent::__construct();
			}
			……your code
	}
in the same directory as index.php

In this way, when you access the index controller through the URL, the system will point to MY_index.php by default and the methods of the original file will be inherited and can be used directly.

System configuration file

File path: root directory/caches/configs

  • database.php database configuration file
  • system.php system configuration file
  • route.php routing configuration file

Call method

Such as calling web_path in system configuration:

pc_base::load_config('system', web_path ');

CMS entry file:

PHPCMS is developed using the MVC design pattern, access is based on modules and operations, and a single entry mode is used for project deployment and access. Regardless of accessing any module or function, there is only one unified entry.

The entry program is the boot program that handles user requests in the early stage. It is the only one that can be run directly upon request by the end user.

File path: root directory/index.php

<?php
	define('PHPCMS_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
	include PHPCMS_PATH.'/phpcms/base.php';
	pc_base::creat_app();
?>

This code first loads the boot file base.php of the phpcms framework, and then it creates a Web application instance and runs it based on the specified configuration file.

PHPCMS framework entry file:

File path: root directory/phpcms/base.php The code snippet is as follows:

<?php
	define('IN_PHPCMS', true);
	define('PC_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
	if(!defined('PHPCMS_PATH')) define('PHPCMS_PATH', PC_PATH.'..'.DIRECTORY_SEPARATOR);
	define('CACHE_PATH', PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR);
……
?>

This file is the framework entry file, including instantiating system/module class methods, calling system/module methods, common system constants, etc. Such as:

	pc_base::load_model(‘*_model’) 加载数据库模型 pc_base::load_sys_class(‘classname’) 实例化系统类
	pc_base::load_app_class(‘classname’,’admin’) 实例化模块类
	pc_base::load_sys_func (‘funcfile’) 调用系统函数库

Global function file:

File path: root directory/phpcms/libs/functions/global.func.php The code snippet is as follows:

<?php
	function new_addslashes($string){
	if(!is_array($string)) return addslashes($string);
	foreach($string as $key => $val) $string[$key] = new_addslashes($val);
	return $string;
	}
	……
?>

The functions in this file are system-wide basic functions and can be called directly in the system.

Secondary development skills:

If you need to add your own global function, you can add it to /phpcms/libs/functions/global.func.php/extention.func.php as needed, which will not affect the upgrade

Data model base class:

File path: root directory/phpcms/libs/classes/model.class.php The code snippet is as follows:

<?php
	pc_base::load_sys_class('db_factory', '', 0);
	class model {  //数据库配置
	protected $db_config = ''; //数据库连接
	protected $db = ''; //调用数据库的配置项
	protected $db_setting = 'default'; //数据表名
	protected $table_name = ''; //表前缀
	public $db_tablepre = '';
	……
?>

After loading the data model, you can use the methods in the database class to perform database operations.

Form call class:

File path: root directory/phpcms/libs/classes/form.class.php. The code snippet is as follows:

<?php
	class form {
	//编辑器调用
	public static function editor($textareaid = 'content', $toolbar = 'basic', $module = '', $catid = '', $color = '', $allowupload = 0, $allowbrowser = 1,$alowuploadexts = '',$height = 200,$disabled_page = 0) {
	} 
	//图片上传调用
	public static function images($name, $id = '', $value = '', $moudle='', $catid='', $size = 50, $class = '', $ext = '', $alowexts = '',$thumb_setting = array(),$watermark_setting = 0 ) {
	}
	……
?>

By instantiating this class, you can call the editor, form upload, date selection, column structure and other forms in the program. Instantiation method: pc_base::load_sys_class('form', '', 0);

Template parsing cache class:

File path: root directory/phpcms/libs/classes/template_cache.class.php. The code snippet is as follows:

<?php
	final class template_cache {
	public function template_compile($module, $template, $style = ‘default’)     {
	$tplfile = $_tpl = PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html'; 
	……
	?>

This class is used to parse templates, parse templates and update template cache

PHPCMS V9 secondary development

PHPCMS URL access:

PHPCMS是采用MVC设计模式开发,基于模块和操作的方式进行访问,采用单一入口模式进行项目部署和访问,无论访问任何一个模块或者功能,只有一个统一的入口。

参数名称 描述 位置 备注

  • M 模型/模块名称 phpcms/modules中模块目录名称 必须
  • C 控制器名称 phpcms/modules/模块/*.php 文件名称 必须
  • A 事件名称 phpcms/modules/模块/*.php 中方法名称

模块访问方法[示例]:

二次开发命名规范

类文件需要以.class.php为后缀(这里是指的phpcms的系统类库文件和模块中的类库文件,第三方引入的不做要求),例如http.class.php。

函数文件需要以.func.php为后缀(第三方引入的不做要求),例如mail.func.php。

类名和文件名一致,例如 phpcmsapp类的文件命名是phpcmsapp.class.php。

数据模型需要以“数据表名称_model.class.php”为形式,类名称与文件名必须相同。

二次开发开发流程

创建数据库模型类

数据库模型位于:phpcms/model/目录下。

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

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

<?php
  defined('IN_PHPCMS') or exit('No permission resources.');
  pc_base::load_sys_class('model', '', 0);
  class test_model extends model {
    public function __construct() {
    $this->db_config = pc_base::load_config('database');
    $this->db_setting = ‘default'; 
    $this->table_name = 'test';
    parent::__construct();
  }
 }
?>

数据库模型类名称必须与文件名称相同;

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

创建模块

如果要创建一个模块,只要在 phpcms/modules 目录下创建文件夹并放入你的控制器类就可以了。

例如要开发一个叫做test的模块,那么首先在phpcms/modules 目录下创建文件夹,并将其命名为test。模块的标准结构通常是这样的。

如果您的模板有单独的前台模板,你需要在phpcms/templates/default下创建一个您的模块目录来放置前台模板,"default"为你的风格包名称,我们默认适用default

访问test模块示例:http://www.yourname.com/index.php?m=test

创建模块控制器类

为test模块增加一个名为myest的控制器 文件路径:根目录/phpcms/modules/test/mytest.php。 代码片段如下:

<?php
  defined('IN_PHPCMS') or exit('No permission resources.');
    class mytest {
      function __construct() {
      }
      public function init() {
        $var = 'hello world!';
        echo $myvar;
      }
      public function mylist() {
        $var = 'hello world!this is a example!';
        echo $myvar;
      }
  }
?>

常用操作列表(1)

1.调用数据库模型

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

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

2.加载系统类

$http = pc_base::load_sys_class('http'); //实例化http类
pc_base::load_sys_class('format', '', 0); //调用form类,不进行实例化操作3.加载系统函

3.加载系统函数库

pc_base::load_sys_func('mail'); //调用mail函数包

4. 加载模块类

$test = pc_base::load_sys_class(‘classname‘,’test’); //实例化test模块下 classname类

5.加载模块函数库

pc_base::load_sys_func(‘global‘,’test’); //调用test模块的global函数包

常用操作列表(2)

6.加载前台模板

include template('test', 'mytest', 'default');

7.加载后台模板

include $this->admin_tpl('mytest_admin_list');

8.权限控制

后台控制控制器需要加载admin模块下的admin类,并继承该类

<?php
	defined('IN_PHPCMS') or exit('No permission resources.');
	pc_base::load_app_class('admin','admin',0);
	class mytest_admin extends admin { 
	//这个控制器需要登录后台才可以访问 }
	?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1137778.htmlTechArticlePHPCMS二次开发教程(转),phpcms二次开发教程 转自:http://www.cnblogs.com/semcoding/p/3347600.html PHPCMS V9 结构设计 根目录 |–api 结构文件目录 |–...
Statement
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
How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

How does PHP handle object cloning (clone keyword) and the __clone magic method?How does PHP handle object cloning (clone keyword) and the __clone magic method?Apr 17, 2025 am 12:24 AM

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP vs. Python: Use Cases and ApplicationsPHP vs. Python: Use Cases and ApplicationsApr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

Describe different HTTP caching headers (e.g., Cache-Control, ETag, Last-Modified).Describe different HTTP caching headers (e.g., Cache-Control, ETag, Last-Modified).Apr 17, 2025 am 12:22 AM

Key players in HTTP cache headers include Cache-Control, ETag, and Last-Modified. 1.Cache-Control is used to control caching policies. Example: Cache-Control:max-age=3600,public. 2. ETag verifies resource changes through unique identifiers, example: ETag: "686897696a7c876b7e". 3.Last-Modified indicates the resource's last modification time, example: Last-Modified:Wed,21Oct201507:28:00GMT.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1?Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1?Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP: An Introduction to the Server-Side Scripting LanguagePHP: An Introduction to the Server-Side Scripting LanguageApr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP and the Web: Exploring its Long-Term ImpactPHP and the Web: Exploring its Long-Term ImpactApr 16, 2025 am 12:17 AM

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

Why Use PHP? Advantages and Benefits ExplainedWhy Use PHP? Advantages and Benefits ExplainedApr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

See all articles

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)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools