php笔记之:初探PHPcms模块开发介绍_php实例
由于工作关系,只能暂时放弃对mongodb的研究了 .开始研究PHPcms .
目前为止我已经基本完成了模块的开发.趁着周末来这里做个总结.我发现phpcms写的还不错,不过文档什么的确实不多.
不说废话了.对于phpcms的模块开发.首先要了解模块的目录结构.
我们可以在http://v9.help.phpcms.cn/html/2010/structure_0928/69.html
找到他的目录结构 我们要开发的东东(也就是模块)就在/phpcms/modules/下面
如果没有什么特别的 在开发一个模块之前先要按照目录结构建立好相关目录并且设计好数据库表结构 比方说 我们建立一个模块叫做我的模块 my_test
下面应该是mytest下的目录结构
mytest
--class //这个是mytest模块会用到的类
--function//mytest模块用到的函数
--install//安装此模块需要的一些配置文件和建立数据表myslq语句什么的在这里
--language//多语言的时候会用到
--config.ini.php//这个配置文件是用来描述整个模块的一些信息
--extention.inc.php//这个是创建目录结构 .这个文件也用来控制权限
--model.php//模块使用了哪些数据模型.(可以理解为使用了哪些表.)
--model.sql//这个向数据库里面插入模型的记录
--my_test.sql//这个文件在安装的时候会被执行,把建立数据库表的sql放进来
--templates //,mytest模块用到的模板文件
--uninstall //卸载模块时候用到的配置和文件
这个里面的文件我没研究 回头研究了补上.
my_test.php //这个是mytest模块的后台控制器文件`
index.php//这个是前台的控制器,这个我没写东西.
建立完一个这样的结构后 我们还需要在/phpcms/model/下面建立我们的数据模型
例如 my_test_model.class.php (这个使用了很典型的工厂模式)
具体每个文件里面写了些什么.我们一个一个来看 .首先来看我们在model文件夹下面写的那个文件.
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';//默认的数据库配置.//多个库的话可以在这里选库
$this->table_name = 'my_test';//这个就是表名称,不用加表前缀
parent::__construct();
}
}
?>
第一行的作用是确定是不是在phpcms的运行框架内.
第二行加载系统的model类,后面的参数0 的意思是并不实例化.
最后一行调用了父类的构造方法.可以在phpcms/libs/classes/model.class.php中找到
而这个model类里面定义了很多对数据的操作方法 最基本的增删改查。以后我再详细说说model基本的一些方法。
接着来看看modules 里面的东东
我们一个个往下面看 第一个language 是用来支持多语言菜单的。
然后是config.ini.php,这个里面写的是一些关于模块安装时候的信息。
文件里面是这个结构的
$module = 'mytest';//使用的model
$modulename = '这里是模块的名称';
$introduce = '模块的描述信息';
$author = '作者';
$authorsite = '作者网站';
$authoremail = '作者email';
里面标注的很清楚了
接着是extention.inc.php 这个文件是用来创建后台管理菜单的目录结构的,也是用来控制权限的
$id= $menu_db->insert(array('name'=>'这里写着操作名称', 'parentid'=>父ID, 'm'=>'模块', 'c'=>'控制器', 'a'=>'动作', 'data'=>'', 'listorder'=>排序, 'display'=>'是否显示'),true);//最后的true是用来返回ID的
文件最后应该有一个数组,这个数组是用来插入系统的\language\zh-cn\system_menu.lang.php里面的 格式如下
$language = array(
'这里是你起的操作名称'=>'这里是操作的中文翻译',
类似:'mytest_init'=>'显示列表'
);
然后是model.php 这个就是你使用了哪些数据模型 可以理解为使用了哪些表
return array('mytest','my_test_artcle');
然后是model.sql 这个是用来向系统的模型表里面插入数据用的
INSERT INTO `phpcms_module` (`module`, `name`, `url`, `iscore`, `version`, `description`, `setting`, `listorder`, `disabled`, `installdate`, `updatedate`) VALUES ();
然后是mytest.sql 建立你数据库表的语句应该写在这个文件里面
接着就是你所使用的模板 应该放在templates里面 命名的规则应该是 mytest_add.tpl.php
最后是你的控制器 这个有的研究了.控制器里面是针对你每个url传递过来的action也就是a=?的动作.默认动作是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;//调用父类的构造函数
}
public function init(){
echo "这里是默认的操作方法";
}
public function add(){
include $this->admin_tpl('mytest_add');//使用模板的方法
}
}
控制器里面写好了 我们把上面的文件都写完了就可以安装我们的模块了 。

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











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 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 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.

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 have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

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.
