1 ก่อนที่จะสร้าง modul จะต้องมีการสร้าง extension ขึ้นทชมาก่อน (วิธีการสร้าง extension)
2.ทำการสร้าง foder ชื่อว่า event ลงใน foder ชื่อ sample1ซึ้งในที่นี้เป็น foder extension
3.เมื่อสร้าง foder ชื่อว่า event เสร็จแล้ว ก็ทำการสร้าง ไฟล์ php โดยให้ชื่อว่า listener
ตัวอย่างโคด ไฟล์ listener.php
โค้ด: เลือกทั้งหมด
<?php
namespace mindphp\sample1\event; //กำหนดชื่อ
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class listener implements EventSubscriberInterface
{
static public function getSubscribedEvents() {
return array(
'core.page_header' => 'page_header',
'core.user_setup' => 'load_language_on_setup',
);//เรียกใช้ event จากที่มีให้ใน phpbb
}
protected $halper;
protected $template;
public function __construct( \phpbb\controller\helper $halper , \phpbb\template\template $template){
$this->halper = $halper;
$this->template = $template;
}//กำหนดตัวแปร construct
public function page_header($event) {
$this->template->assign_vars(array(
'U_MINDPHP_SAMPLE1_PAGE' => $this->halper->route('sample1_controller', array('name' => 'mindphp')),
));
}
public function load_language_on_setup($event) { // function สำหรับเรียกงานภาษา
$lang_set_ext = $event['lang_set_ext'];
$lang_set_ext[] = array(
'ext_name' => 'mindphp/sample1',
'lang_set' => 'sample1',
);
$event['lang_set_ext'] = $lang_set_ext;
}
}
5.สร้างไฟล์ php จำนวน 2 ไฟล์ โดยกำหนดชื่อ ไฟล์ที่ 1 ว่า m_mtb_news_info ส่วนไฟล์ที่ 2 มีชื่อว่า m_mtb_news_module
ตัวอย่างโคด ไฟล์ m_mtb_news_info.php
โค้ด: เลือกทั้งหมด
<?php
namespace mindphp\sample1\acp; //ๅกำหนดชื่อ
if (!defined('IN_PHPBB')) {
exit;
}
class m_mtb_news_info {
function module() {
return array(
'filename' => '\mindphp\sample1\acp\m_mtb_news_module', //เรียกใช้ ไฟล์ modul
'title' => 'ACP_MTB_NEWS_TITLE', //กำหนดชื่อ modul
'version' => '1.0.0',
'modes' => array(
'm_topic_portal' => array('title' => 'ACP_MTB_NEWS_MODES_TITLE', 'auth' => 'ext_mindphp/sample1', 'cat' => array('SAMPLE1_MOD')), //
กำหนดค่า modul
),
);
}
}
โค้ด: เลือกทั้งหมด
<?php
namespace mindphp\sample1\acp;
class m_mtb_news_module {
var $u_action;
function main($id, $mode) {
global $db, $user, $auth, $template, $cache, $request;
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
$this->config = $config;
$this->request = $request;
$this->tpl_name = 'acp_m_mtb_news';
}
}
7.สร้างไฟล์ php โดยกำหนด ชื่อว่า install_sample1
ตัวอย่างโคด ไฟล์ migration.php
โค้ด: เลือกทั้งหมด
<?php
namespace mindphp\sample1\migrations;
class install_sample1 extends \phpbb\db\migration\migration {
public function effectively_installed() {
return isset($this->config['sample1_version']) && version_compare($this->config['sample1'], '1.0.0', '>=');
}
static public function depends_on() {
return array('\phpbb\db\migration\data\v310\dev');
}
public function update_data() {
return array(
array('config.add', array('tmb_news_userid', '1')),
array('config.add', array('tmb_news_usergroup', '')),
array('module.add', array(
'acp',
'ACP_CAT_DOT_MODS',
'ACP_MTB_NEWS_TITLE'
)),
array('module.add', array(
'acp',
'ACP_MTB_NEWS_TITLE',
array(
'module_basename' => '\mindphp\sample1\acp\m_mtb_news_module',
'modes' => array('m_topic_portal'),
),
)),
);
}
}
9.สร้าง ไฟล์ html โดยใช้ชื่อว่า acp_m_show_search_new ลงใน foder ชื่อ style
ตัวอย่างโคด ไฟล์ acp_m_show_search_new.html
โค้ด: เลือกทั้งหมด
<!-- INCLUDE overall_header.html -->
<h1>{L_ALERT_PRIVATE_MESSAGE}</h1>
<p>{L_ALERT_PRIVATE_MESSAGE_EXPLAIN}</p>
<form id="acp_share_module" method="post" enctype="multipart/form-data" action="{T_ACTION}">
<fieldset>
<legend>{L_ALERT_PRIVATE_MESSAGE_MODULE}</legend>
<dl>
<dt><label for="module_status">{L_ENABLE_ALERT_PRIVATE_MESSAGE}:</label></dt>
<dd>
<label><input type="radio" class="radio" name="m_show_search_alert" value="1" <!-- IF ENABLE_PRIVATE_MESSAG == 1 --> checked="checked" <!-- ENDIF--> />{L_YES}</label>
<label><input type="radio" class="radio" name="m_show_search_alert" value="0" <!-- IF ENABLE_PRIVATE_MESSAG != 1 --> checked="checked"<!-- ENDIF--> /> {L_NO}</label>
</dd>
</dl>
</fieldset>
<p class="submit-buttons">
<input class="button1" type="submit" id="submit" name="submit" value="{L_SUBMIT}" />
<input class="button2" type="reset" id="reset" name="reset" value="{L_RESET}" />
{S_FORM_TOKEN}
</p>
</form>
<!-- INCLUDE overall_footer.html -->