假设我安装的模块名为 "mytest"
步骤如下:
1.新建文件夹 /phpcms/modules/mytest,在 mytest 下新建3个文件夹和2个文件,如上图红色线框.
install:安装文件存放文件夹
uninstall:卸载文件存放文件夹
templates:后台模板文件存放文件夹
index.php:前台控制器
mytest_admin.php:后台控制器
index.php 文件内容:
- <?php
- defined('IN_PHPCMS') or exit('No permission resources.');
- class index {
- public function init(){
- echo '模块mytest前台控制器的默认方法';
- }
- public function test(){
- include template('mytest', '1'); // 输出模板:mytest 模块下的 1.html (1.html内容请往下看!)
- }
- }
- ?>
mytest_admin.php 文件内容:
- <?php
- defined('IN_PHPCMS') or exit('No permission resources.');
- pc_base::load_app_class('admin', 'admin', 0);
- class mytest_admin extends admin {
- public function __construct() {
- parent::__construct(); // 必须先执行父类 admin 的构造方法
- }
- public function init(){
- include $this->admin_tpl('index'); // 模块mytest的后台菜单---默认页:mytest/templates/index.tpl.php
- } //Vevb.com
- public function setting(){
- include $this->admin_tpl('setting'); // 模块mytest的后台菜单---设置页:mytest/templates/setting.tpl.php
- }
- }
- ?>
templates/index.tpl.php
- <?php defined('IN_ADMIN') or exit('No permission resources.');?>
- <?php include $this->admin_tpl('header', 'admin');?>
- 模块mytest的后台菜单---默认页
- </body>
- </html>
templates/setting.tpl.php
- <?php defined('IN_ADMIN') or exit('No permission resources.');?>
- <?php include $this->admin_tpl('header', 'admin');?>
- 模块mytest的后台菜单---设置页
- </body>
- </html>
2.在 mytest/install/ 下,新建 languages/zh-cn/mytest.lang.php、templates/1.html、config.inc.php、extension.inc.php、model.php、module.sql、mytest.sql 文件.
/phpcms/modules/mytest/install/languages/zh-cn/mytest.lang.php:语言文件,此文件将被复制到 /phpcms/languages/zh-cn/mytest.lang.php.
- <?php
- $LANG['setting_updates_successful'] = '配置更新完成';
- ?>
/phpcms/modules/mytest/install/templates/1.html:前台模板,此文件将被复制到 /phpcms/templates/default/mytest/1.html
前台页面访问测试:www.Vevb.com/index.php?m=mytest&c=index&a=test
/phpcms/modules/mytest/install/config.inc.php:模块相关介绍信息
- <?php
- defined('IN_PHPCMS') or exit('Access Denied');
- defined('INSTALL') or exit('Access Denied');
- $module = 'mytest';
- $modulename = '我的测试模块';
- $introduce = '我的测试模块cccccc';
- $author = 'malinjie66 team';
- $authorsite = 'http://www.Vevb.com';
- $authoremail = 'malinjie66@126.com';
- ?>
/phpcms/modules/mytest/install/extension.inc.php:模块后台管理的菜单
- <?php
- defined('IN_PHPCMS') or exit('Access Denied');
- defined('INSTALL') or exit('Access Denied');
- $parentid = $menu_db->insert(array('name'=>'mytest', 'parentid'=>'29', 'm'=>'mytest', 'c'=>'mytest_admin', 'a'=>'init', 'data'=>'', 'listorder'=>0, 'display'=>'1'), true); // 这个菜单会显示在左侧
- $menu_db->insert(array('name'=>'mytest_setting', 'parentid'=>$parentid, 'm'=>'mytest', 'c'=>'mytest_admin', 'a'=>'setting', 'data'=>'', 'listorder'=>0, 'display'=>'1')); // 这个菜单会显示在右侧页签
- $language = array('mytest'=>'测试XX', 'mytest_setting'=>'设置'); // 给菜单设置中文显示词
- ?>
/phpcms/modules/mytest/install/model.php:模型文件(该文件返回一个数组,所以可以有多个模型文件)
- <?php
- defined('IN_PHPCMS') or exit('Access Denied');
- defined('INSTALL') or exit('Access Denied');
- return array('mytest'); // 模型文件 /phpcms/model/mytest_model.class.php 必须手动建立!内容如下:
- ?>
/phpcms/model/mytest_model.class.php
- <?php
- defined('IN_PHPCMS') or exit('No permission resources.');
- pc_base::load_sys_class('model', '', 0);
- class mytest_model extends model {
- function __construct() {
- $this->db_config = pc_base::load_config('database'); // 加载数据库配置
- $this->db_setting = 'default'; // 连接默认数据库
- $this->table_name = 'mytest'; // 设置表名
- parent::__construct(); // 执行 model 类的构造方法
- }
- }
- ?>
/phpcms/modules/mytest/install/module.sql:在module表中插入一条记录(mytest模块相关的信息)
- INSERT INTO `phpcms_module` (`module`, `name`, `url`, `iscore`, `version`, `description`, `setting`, `listorder`, `disabled`, `installdate`, `updatedate`) VALUES ('mytest', '我的测试模块', 'mytest/', 0, '1.0', '我的测试模块', '', 0, 0, '2013-10-05', '2013-10-12');
/phpcms/modules/mytest/install/mytest.sql:mytest模块要用到的表结构
- DROP TABLE IF EXISTS `phpcms_mytest`;
- CREATE TABLE IF NOT EXISTS `phpcms_mytest` (
- `id` int(10) unsigned NOT NULL auto_increment,
- `catid` int(10) unsigned NOT NULL default '0' COMMENT '栏目id',
- `siteid` mediumint(6) unsigned NOT NULL default '0' COMMENT '站点ID',
- `contentid` int(10) unsigned NOT NULL default '0' COMMENT '文章id',
- `total` int(10) unsigned NOT NULL default '0' COMMENT '总数',
- `n1` int(10) unsigned NOT NULL default '0',
- `n2` int(10) unsigned NOT NULL default '0',
- `n3` int(10) unsigned NOT NULL default '0',
- `lastupdate` int(10) unsigned NOT NULL default '0' COMMENT '最后更新时间',
- PRIMARY KEY (`id`),
- KEY `total` (`total`),
- KEY `lastupdate` (`lastupdate`),
- KEY `catid` (`catid`,`siteid`,`contentid`)
- ) TYPE=MyISAM;
3.在 mytest/uninstall/ 下,新建 extension.inc.php、model.php、mytest.sql.
extension.inc.php 文件内容:
- <?php
- defined('IN_PHPCMS') or exit('Access Denied');
- defined('UNINSTALL') or exit('Access Denied');
- ?>
model.php 文件内容:
- <?php
- defined('IN_PHPCMS') or exit('Access Denied');
- defined('UNINSTALL') or exit('Access Denied');
- return array('mytest');
- ?>
mytest.sql 文件内容:
DROP TABLE IF EXISTS `phpcms_mytest`;
访问效果:
extention.inc.php 千万不要写成 extension.inc.php.
新闻热点
疑难解答