PHP技術交流羣:180460365、320205320
今天要修改discuz的一點東西,想添加一個頁面。作爲一個老牌的PHP論壇系統。一直以來都聽過他的名聲。
但是真沒做過啊。
於是花了點時間看了下。
假如我們想要增加discuz一個頁面是http://sex.linglingtang.com/test.php?mod=my
首先:建 \test.php(入口)
即在根目錄新建一個php文件,就叫 test.php ,這個是入口文件;
然後:建 \source\class\class_test.php(類)
即在\source\class 新建模塊類文件 class_test.php ,在裏面添加my類;
然後:建 \source\function\function_test.php(方法)
即在\source\function,定義不同的mod方法;
然後:建 \source\module\test\test_my.php(後端控制器)
即在\source\module 新增 test文件夾,在test文件夾新增文件 test_模塊名.php;
然後:建 \template\default\test\my.htm(前端模板)
即在默認主題/theme/default/ 新建test文件夾,在test文件夾裏新建模板文件my.htm , 也就是theme/default/test/my.htm;
代碼如下:
\test.php
<?php
define('APPTYPEID', 0);
define('CURSCRIPT', 'test');
require './source/class/class_core.php';
$discuz = C::app();
$modarray = array('my');
if(!isset($_GET['mod']) && !in_array($_GET['mod'],$modarray)){
die('mod is undefined!');
}
$mod = isset($_GET['mod']) ? $_GET['mod']:'my';
define('CURMODULE', $mod);
$discuz->init();
require libfile('function/test');
require libfile('class/test');
runhooks();
require DISCUZ_ROOT.'./source/module/test/test_'.$mod.'.php';
\source\class\class_test.php
<?php
/**
* Yoper test
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class my{
function __construct($msg){
my($msg);
}
function run(){
return "www.linlingtang.com";
}
}
?>
\source\function\function_test.php
<?php
/**
* Yoper add
*/
function my($msg){
echo "~ my ~";
}
\source\module\test\test_my.php
<?php
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
define('NOROBOT', TRUE);
$c = new my("hello,my");
$time = $c->run();
include template('test/my');
\template\default\test\my.htm
<!--{template common/header}-->
<div class="my">
<br><br><br><br><br>
<center>my頁面</center>
<br><br><br><br>
</div>
<!--{template common/footer}-->
discuz新增頁面效果圖(這不是默認主題)
廣告時間~~~~~~~
現在的公衆號,都是女博情感啊、雞湯啊。動不動就幾十萬閱讀。
我們辛辛苦苦碼代碼一個月。還不如人家一篇雞湯文賺得多。
碼農轉型中,歡迎關注我時不時瞎吐槽的個人公衆號——零零糖。
PHP技術交流羣:180460365、320205320