discuz新增一个discuz 独立页面

想单独新增一个自定义的独立页面类似dz的member页面,经过尝试基本实现了单页功能:过程如下:

比如想新建一个test.php,则整个MVC过程如下:

upload根目录下新增test.php 【入口文件】

template/default下新建test文件夹,文件夹下新建你所定义的mod文件名,【模板文件】 比如test.php?mod=run,则对应的模板文件为template/default/test/run.php 

source下class文件夹中新增class_test.php 【模块类文件】比如mod定义为run,则该文件里面添加run类及其方法,如果定义了多个mod则声明多个模块类

source下function文件夹中新增function_test.php【模块函数】这里可以分别定义不同mod的方法以及公共方法

source下module文件夹中新增test文件夹,该文件中增加一些文件,文件名根据你在test.php中定义的$modarray的名称来创建【实例文件】:命名规则为test_模块名.php


我定义了run,laugh,talk三个模块,实际test.php的效果如下:

默认地址:http://www.bbs.com/test.php


run模块地址:http://www.bbs.com/test.php?mod=run



laugh模块地址:http://www.bbs.com/test.php?mod=laugh


入口文件test.php

<?php  
define('APPTYPEID', 0);  
define('CURSCRIPT', 'test');  
  
require './source/class/class_core.php';  
$discuz = C::app();  
//echo "<pre/>";  
//print_r($discuz);  
$modarray = array('talk', 'laugh','run');  
  
if(!!isset($_GET['mod']) && !in_array($_GET['mod'],$modarray)){  
    echo('mod is undefined!');  
}  
  
$mod = isset($_GET['mod']) ? $_GET['mod']:'talk';//有个方法判断当前的model  
define('CURMODULE', $mod);  
$discuz->init();  
  
require libfile('function/test');  
require libfile('class/test');  
runhooks();  
require DISCUZ_ROOT.'./source/module/test/test_'.$mod.'.php';  
?>  


function文件:

source/function/function_test.php

[php]  view plain  copy
  1. <?php  
  2. if(!defined('IN_DISCUZ')) {  
  3.     exit('Access Denied');  
  4. }  
  5.   
  6. function talk($msg){  
  7.     echo "new ".__FUNCTION__." model and runing in ".__FUNCTION__." model,".$msg;  
  8. }  
  9.   
  10. function laugh($msg){  
  11.     echo "new ".__FUNCTION__." model and runing in ".__FUNCTION__." model,".$msg;  
  12. }  
  13.   
  14. function run($msg){  
  15.     echo "new ".__FUNCTION__." model and  runing in ".__FUNCTION__." model,".$msg;  
  16. }  
  17. ?>  



class类文件:

source/class/class_test.php

[php]  view plain  copy
  1. <?php  
  2. if(!defined('IN_DISCUZ')) {  
  3.     exit('Access Denied');  
  4. }  
  5.   
  6. class talk{  
  7.     function __construct($msg){  
  8.         talk($msg);  
  9.     }  
  10.     function  run(){  
  11.         return "now in ".__CLASS__." model ,time is:".date("Y-m-d H:i:s",time());  
  12.     }  
  13. }  
  14.   
  15. class laugh{  
  16.     function __construct($msg){  
  17.         laugh($msg);  
  18.     }  
  19.     function  run(){  
  20.         return "now in ".__CLASS__." model ,time is:".date("Y-m-d H:i:s",time());  
  21.     }  
  22. }  
  23.   
  24. class run{  
  25.   
  26.     function __construct($msg){  
  27.         run($msg);  
  28.     }  
  29.     function  run(){  
  30.         return "now in ".__CLASS__." model ,time is:".date("Y-m-d H:i:s",time());  
  31.     }  
  32. }  
  33. ?>  


模块实例文件:【多个以此类推】

source/module/test/test_laugh.php 

[php]  view plain  copy
  1. <?php  
  2. if(!defined('IN_DISCUZ')) {  
  3.     exit('Access Denied');  
  4. }  
  5. define('NOROBOT', TRUE);  
  6. //echo "hello world! I can laugh";  
  7. $c = new laugh("hello,laugh");  
  8. $time = $c->run();  
  9. include template('test/laugh');  
  10. ?>  


模板文件:【多个以此类推】

template/default/test/llaugh.php

[php]  view plain  copy
  1. <!--{template common/header}-->  
  2.  <style>  
  3.      .talk{padding: 2em;}  
  4.      .talk p{font-size: 30px;border: 5px solid #F0F2F2;padding: 2em;border-radius: 2px;}  
  5.      .talk p span{font-size: 12px;display: inline-block;margin-right: 2px;margin-left: 2em;}  
  6.  </style>  
  7. <div class="talk">  
  8.     <p>独立的laughing页面,<span>{$time}</span></p>  
  9.   
  10. </div>  
  11. <!--{template common/footer}-->  

到此,一个简单的discuz单页就做好了,然后根据个人需要引入数据,让模板填充数据自由发挥。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值