Discuz! X2.5 Add a custom data call module (simple method)
Turn: http://521-wf.com/archives/46.html
Discuz! X2.5 Add a custom data call module (simple method)
Function Discuz! The X Series Dista is still pretty good. In the process of secondary development, you can add a new data call module to develop the functional module that you are developing, you can display the data that you want to display in each place of each page.
Below is a brief introduction to the latest version of X2.5:
This can be roughly divided into the following three steps:
1. Add a data call program
2. Cache classification of DIY modules
3. Add the appropriate data template
The specific operation is as follows:
1. Add a data call program
1> New folders in the source/class/block/directory
2>
In the news folder, create a new one Blockclass.php , the content is as follows:
<?php
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
$blockclass = array(
'name' => lang('blockclass', 'blockclass_resource'),
);
?>
Then create a new one in the news folder block_news.php , the content is as follows:
<?php
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class block_news extends discuz_block {
public $setting = array();
public function block_news() {
$ this-> setting = array (.........); // initialize the setup here
}
public function name() {
// Set the data source here
return lang('blockclass', 'blockclass_news_script_news');
}
public function blockclass() {
// Set the type of the call module here
return array('news', lang('blockclass', 'blockclass_news'));
}
public function fields() {
$ Fields = array (.........); // Set the fields here. With the exception of variables supported by the disk itself, only the fields set here can be called in the template.
return $fields;
}
public function getsetting() {
return $this->setting;
}
public function getdata($style, $parameter) {
$ list = array (.........); // from the actual situation, from the actual situation, the relevant data can be
return array('html' => ", 'data' => $list);
}
}
?>
Lang (....) in the above code, this is the language processing that is skipped here. There are also settings $, $Fields, list formats $. You can refer to the format of the corresponding variable in Source/Class/Block/Member/Block_member.php .
Secondly, enter the background-lifting cache, be sure to check the "DIY Module Classification Cache", and then start updating.
Third, enter the background portal module template, add the appropriate template to this.