Home > Backend Development > PHP Tutorial > PHPCMS secondary development tutorial (transfer), phpcms secondary development tutorial_PHP tutorial

PHPCMS secondary development tutorial (transfer), phpcms secondary development tutorial_PHP tutorial

WBOY
Release: 2016-07-12 08:49:19
Original
874 people have browsed it

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
	}
Copy after login
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();
?>
Copy after login

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);
……
?>
Copy after login

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’) 调用系统函数库
Copy after login

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;
	}
	……
?>
Copy after login

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 = '';
	……
?>
Copy after login

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 ) {
	}
	……
?>
Copy after login

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'; 
	……
	?>
Copy after login

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();
  }
 }
?>
Copy after login

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

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

创建模块

如果要创建一个模块,只要在 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;
      }
  }
?>
Copy after login

常用操作列表(1)

1.调用数据库模型

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

其中$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.加载系统函
Copy after login

3.加载系统函数库

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

4. 加载模块类

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

5.加载模块函数库

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

常用操作列表(2)

6.加载前台模板

include template('test', 'mytest', 'default');
Copy after login

7.加载后台模板

include $this->admin_tpl('mytest_admin_list');
Copy after login

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 { 
	//这个控制器需要登录后台才可以访问 }
	?>
Copy after login

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1137778.htmlTechArticlePHPCMS二次开发教程(转),phpcms二次开发教程 转自:http://www.cnblogs.com/semcoding/p/3347600.html PHPCMS V9 结构设计 根目录 |–api 结构文件目录 |–...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template