假設我安裝的模塊名為 "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內容請往下看?。?nbsp;
- }
- }
- ?>
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.49028c.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.49028c.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.
新聞熱點
疑難解答