discuz二次开发-门户下面diy模块(全能调取数据)

discuz二次开发-门户下面diy模块(全能调取数据)

     当我在做 discuz 二次开发的时候,我添加了一个功能,我想在任何一个页面去调用数据,也想使用discuz的前台diy模式去调用这些数据,这个时候就需要你自己写代码了哦,自己写模块。下面是详细介绍。

先看下效果:我把我自己的文件写在了其他模块下面


模块开发一定要遵循discuz的规则,按照它规定的一些规则走:
discuz的所有的模块全部在:source/class/block 中,看下对应的文件就明白了


这个时候差不多明白一点了吧!

下面咱们在其它类中自定义一个咱们自己的吧


我现在other目录中新建一个block_othernew.php 文件 必须为block_(自定义的名称).php这种格式

其实你在新建一个文件也是可以的 ,可以参考other文件下面的文件,必须存在blockclass.php 这个文件,这个文件:
$blockclass = array(
'name' => lang('blockclass', 'blockclass_other'),//里面定义的就是语言包,就死上图中的 其他类,可以找下语言包中的这个字段,看下就明白了。
);

接着block_othernew.php 

if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}


class block_othernew extends discuz_block {


function block_otherstat() {}
    
//模块名称 模块分类
function name() {
return "自己模块";
}
function blockclass(){
//othernew 模块总分类
return array('othernew', "模块杀手");
}
    //这个模块要返回的字段
function fields() {
return array(
'posts' => array('name' => lang('blockclass', 'blockclass_other_stat_posts'), 'formtype' => 'text', 'datatype' => 'int'),
'posts_title' => array('name' => lang('blockclass', 'blockclass_other_stat_posts_title'), 'formtype' => 'text', 'datatype' => 'string'),
);
}
//设置需要帅选的参数 然后参数会自动传给  etdata($style, $parameter)
function getsetting() {
global $_G;
$settings = array(
'titlelength' => array(
'title' => '傻了吧唧',
'type' => 'text',
'default' => ""
)
);
return $settings;
}
        //返回数据的函数,自己发挥吧,一定要保证你返回的字段 在上个 fields 函数里面要有
function getdata($style, $parameter) {
global $_G;
$parameter = $this->cookparameter($parameter);
$fields = array(
'posts' => 0,
'posts_title' => !empty($parameter['posts_title']) ? $parameter['posts_title'] : lang('block/stat', 'stat_posts'),
);
if(in_array('posts', $parameter['option']) || in_array('bbsnewposts', $parameter['option'])) {
$sql = "SELECT sum(f.posts) AS posts, sum(f.todayposts) AS todayposts FROM ".DB::table('forum_forum')." f WHERE f.status='1'";
$forum = DB::fetch_first($sql);
}
if(in_array('posts', $parameter['option'])) {
$fields['posts'] = intval($forum['posts']);
}
$list = array();
return array('html' => '', 'data' => $list);
}
}


?>

以上类中的函数必须有,缺少一个不可,这是更新一下工具->更新缓存-》 DIY 模块分类缓存 更新一下缓存即可,这是去后台和前台看下吧有没有!

要是想要调用最好先在后台为你的模块添加模板:

门户=》模板模块=》添加 ,选中你刚才自定义的模块,点击提交,看下图:看看里面的字段,是不是和你定义的类中fields 函数里面的字段是一样的吧!





添加模板,添加好之后,就可以去DIY了,去试试吧.有时你你可以看下 这个函数,相信你会有收获,





这个目录下。

希望能帮到每个程序员



  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值