新增一个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 if(!defined("IN_DISCUZ")) { exit("Access Denied"); } function talk($msg){ echo "new ".__FUNCTION__." model and runing in ".__FUNCTION__." model,".$msg; } function laugh($msg){ echo "new ".__FUNCTION__." model and runing in ".__FUNCTION__." model,".$msg; } function run($msg){ echo "new ".__FUNCTION__." model and runing in ".__FUNCTION__." model,".$msg; } ?>
class类文件:
source/class/class_test.php
<?php if(!defined("IN_DISCUZ")) { exit("Access Denied"); } class talk{ function __construct($msg){ talk($msg); } function run(){ return "now in ".__CLASS__." model ,time is:".date("Y-m-d H:i:s",time()); } } class laugh{ function __construct($msg){ laugh($msg); } function run(){ return "now in ".__CLASS__." model ,time is:".date("Y-m-d H:i:s",time()); } } class run{ function __construct($msg){ run($msg); } function run(){ return "now in ".__CLASS__." model ,time is:".date("Y-m-d H:i:s",time()); } } ?>
模块实例文件:【多个以此类推】
source/module/test/test_laugh.php
<?php if(!defined("IN_DISCUZ")) { exit("Access Denied"); } define("NOROBOT", TRUE); //echo "hello world! I can laugh"; $c = new laugh("hello,laugh"); $time = $c->run(); include template("test/laugh"); ?>
模板文件:【多个以此类推】
template/default/test/llaugh.php
<!--{template common/header}--> <style> .talk{padding: 2em;} .talk p{font-size: 30px;border: 5px solid #F0F2F2;padding: 2em;border-radius: 2px;} .talk p span{font-size: 12px;display: inline-block;margin-right: 2px;margin-left: 2em;} </style> <div class="talk"> <p>独立的laughing页面,<span>{$time}</span></p> </div> <!--{template common/footer}-->
到此,一个简单的discuz单页就做好了,然后根据个人需要引入数据,让模板填充数据自由发挥。