密通学院

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 5426|回复: 0

[开发] 新增一个discuz 独立页面

[复制链接]
  • TA的每日心情
    可爱
    2018-6-29 10:04
  • 289

    主题

    319

    帖子

    9万

    铜板

    超级版主

    Rank: 8Rank: 8

    积分
    93815
    QQ
    发表于 2017-7-17 12:40:12 | 显示全部楼层 |阅读模式

    马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    本帖最后由 mt 于 2017-7-17 12:46 编辑

    想单独新增一个自定义的独立页面类似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] view plain copy


    • define('APPTYPEID', 0);  
    • define('CURSCRIPT', 'test');  
    •   
    • require './source/class/class_core.php';  
    • $discuz = C::app();  
    • //echo "";  
    • //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


    • 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] view plain copy


    • 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] view plain copy


    • 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


    [php] view plain copy


    •   
    •    
    •   
    •     独立的laughing页面,{$time}
        
    •   

    •   
    •   




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

    如果您有业务需求,可以和我联系:http://wpa.qq.com/msgrd?V=3& ... yes&from=discuz
    回复

    使用道具 举报

    快速回复: 支持 高兴 激动 给力 加油 苦寻 生气 回帖 路过 感恩
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    首页|Archiver|手机版|小黑屋|密通学院:专业网络营销服务商

    GMT+8, 2024-3-29 13:42 , Processed in 0.130860 second(s), 27 queries QQ

    Powered by XMT Inc. © 2015-2025 ArrayV1.0 豫ICP备17022382号

    系统运营:密城通 豫公网安备 41018302000212 号

    快速回复 返回顶部 返回列表