discuz二次开发-门户下面diy模块(全能调取数据)
2015-08-07 11:52
603 查看
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了,去试试吧.有时你你可以看下 这个函数,相信你会有收获,
这个目录下。
希望能帮到每个程序员
当我在做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了,去试试吧.有时你你可以看下 这个函数,相信你会有收获,
这个目录下。
希望能帮到每个程序员
相关文章推荐
- 如何修改报表平台中数据决策系统登陆地址
- Spark MLlib LDA主题模型
- IIS500的问题
- jquery 根据输入框输入的值 自动计算其他值的实例
- 右侧跟随滚动框(调用框架)
- 9.6智力题(二)——九球称重
- 数组名作函数参数
- 52. Element item() 方法
- hadoop序列化机制与java序列化机制对比
- hdu 1686 Oulipo
- run_time library
- 51. Element replaceChild() 方法
- UVa11991(map+vector)
- centOS配置mysql+appache+vsftp=php服务器
- Android圆角Tag控件的另类实现
- win8.1 64位环境建设android开发环境
- Struts2里面 s:textfield标签 Date类型的格式化以及日期时间控件使用
- 互联网公司2014前端笔试面试题:JavaScript篇
- 初次使用ticcs注意事项
- websocket入门指南