


PHPCMS secondary development tutorial (transfer), phpcms secondary development tutorial_PHP tutorial
Jul 12, 2016 am 08:49 AMPHPCMS 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’) 加載數(shù)據(jù)庫(kù)模型 pc_base::load_sys_class(‘classname’) 實(shí)例化系統(tǒng)類(lèi) pc_base::load_app_class(‘classname’,’admin’) 實(shí)例化模塊類(lèi) pc_base::load_sys_func (‘funcfile’) 調(diào)用系統(tǒng)函數(shù)庫(kù)
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 { //數(shù)據(jù)庫(kù)配置 protected $db_config = ''; //數(shù)據(jù)庫(kù)連接 protected $db = ''; //調(diào)用數(shù)據(jù)庫(kù)的配置項(xiàng) protected $db_setting = 'default'; //數(shù)據(jù)表名 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 { //編輯器調(diào)用 public static function editor($textareaid = 'content', $toolbar = 'basic', $module = '', $catid = '', $color = '', $allowupload = 0, $allowbrowser = 1,$alowuploadexts = '',$height = 200,$disabled_page = 0) { } //圖片上傳調(diào)用 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設(shè)計(jì)模式開(kāi)發(fā),基于模塊和操作的方式進(jìn)行訪問(wèn),采用單一入口模式進(jìn)行項(xiàng)目部署和訪問(wèn),無(wú)論訪問(wèn)任何一個(gè)模塊或者功能,只有一個(gè)統(tǒng)一的入口。
參數(shù)名稱 描述 位置 備注
- M 模型/模塊名稱 phpcms/modules中模塊目錄名稱 必須
- C 控制器名稱 phpcms/modules/模塊/*.php 文件名稱 必須
- A 事件名稱 phpcms/modules/模塊/*.php 中方法名稱
模塊訪問(wèn)方法[示例]:
二次開(kāi)發(fā)命名規(guī)范
類(lèi)文件需要以.class.php為后綴(這里是指的phpcms的系統(tǒng)類(lèi)庫(kù)文件和模塊中的類(lèi)庫(kù)文件,第三方引入的不做要求),例如http.class.php。
函數(shù)文件需要以.func.php為后綴(第三方引入的不做要求),例如mail.func.php。
類(lèi)名和文件名一致,例如 phpcmsapp類(lèi)的文件命名是phpcmsapp.class.php。
數(shù)據(jù)模型需要以“數(shù)據(jù)表名稱_model.class.php”為形式,類(lèi)名稱與文件名必須相同。
二次開(kāi)發(fā)開(kāi)發(fā)流程
創(chuàng)建數(shù)據(jù)庫(kù)模型類(lèi)
數(shù)據(jù)庫(kù)模型位于:phpcms/model/目錄下。
數(shù)據(jù)模型文件的命名規(guī)則建議為數(shù)據(jù)表名稱+'_model.class.php'
如果在我們的創(chuàng)建的模塊中我要使用一個(gè)數(shù)據(jù)庫(kù)“test”,首先需要建立一個(gè)數(shù)據(jù)庫(kù)模型文件,文件名稱為'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(); } } ?>
數(shù)據(jù)庫(kù)模型類(lèi)名稱必須與文件名稱相同;
$this->db_setting = 'default'為數(shù)據(jù)庫(kù)配置文件中配置數(shù)據(jù)庫(kù)鏈接池名稱,默認(rèn)為default,一般情況下不需要修改。 $this->table_name = ‘test’為數(shù)據(jù)表名稱
創(chuàng)建模塊
如果要?jiǎng)?chuàng)建一個(gè)模塊,只要在 phpcms/modules 目錄下創(chuàng)建文件夾并放入你的控制器類(lèi)就可以了。
例如要開(kāi)發(fā)一個(gè)叫做test的模塊,那么首先在phpcms/modules 目錄下創(chuàng)建文件夾,并將其命名為test。模塊的標(biāo)準(zhǔn)結(jié)構(gòu)通常是這樣的。
如果您的模板有單獨(dú)的前臺(tái)模板,你需要在phpcms/templates/default下創(chuàng)建一個(gè)您的模塊目錄來(lái)放置前臺(tái)模板,"default"為你的風(fēng)格包名稱,我們默認(rèn)適用default
訪問(wèn)test模塊示例:http://www.yourname.com/index.php?m=test
創(chuàng)建模塊控制器類(lèi)
為test模塊增加一個(gè)名為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.調(diào)用數(shù)據(jù)庫(kù)模型
$this->db = pc_base::load_model('test_model');
其中$this->db中所支持的方法請(qǐng)參照phpcms/libs/classes/model.class.php中方法
2.加載系統(tǒng)類(lèi)
$http = pc_base::load_sys_class('http'); //實(shí)例化http類(lèi) pc_base::load_sys_class('format', '', 0); //調(diào)用form類(lèi),不進(jìn)行實(shí)例化操作3.加載系統(tǒng)函
3.加載系統(tǒng)函數(shù)庫(kù)
pc_base::load_sys_func('mail'); //調(diào)用mail函數(shù)包
4. 加載模塊類(lèi)
$test = pc_base::load_sys_class(‘classname‘,’test’); //實(shí)例化test模塊下 classname類(lèi)
5.加載模塊函數(shù)庫(kù)
pc_base::load_sys_func(‘global‘,’test’); //調(diào)用test模塊的global函數(shù)包
常用操作列表(2)
6.加載前臺(tái)模板
include template('test', 'mytest', 'default');
7.加載后臺(tái)模板
include $this->admin_tpl('mytest_admin_list');
8.權(quán)限控制
后臺(tái)控制控制器需要加載admin模塊下的admin類(lèi),并繼承該類(lèi)
<?php defined('IN_PHPCMS') or exit('No permission resources.'); pc_base::load_app_class('admin','admin',0); class mytest_admin extends admin { //這個(gè)控制器需要登錄后臺(tái)才可以訪問(wèn) } ?>

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

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.

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.

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]

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.

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

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.

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.

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.
