1.ตัวอย่างส่วนโคดที่จะทำการสร้างค่าให้กับ define()
โค้ด: เลือกทั้งหมด
public function memberlist_memberrow_before($event) {
$sql_ray = array(
'SELECT' => 'DISTINCT count(p.post_id) as count_post ,p.user_id,username ',
'FROM' => array(
$this->table_prefix . 'm_anonymous' => 'p',
),
'LEFT_JOIN' => array(
array(
'FROM' => array(USERS_TABLE => 'u'),
'ON' => 'p.user_id = u.user_id',
)),
'WHERE' => ' p.user_id IN (' . implode(',', $user_id_s) . ')' . ' GROUP BY p.user_id ',
);
$sql = $this->db->sql_build_query('SELECT', $sql_ray);
$result = $this->db->sql_query($sql);
$user_post = array();
while ($row = $this->db->sql_fetchrow($result)) {
$user_post[] = $row;
}
$this->db->sql_freeresult($result);
define('USER_DATA', serialize($user_post));//ส่วนนี้จะทำการส่งตัวแปรที่ได้จาก Event ไปใช้งาน
}
โค้ด: เลือกทั้งหมด
public function memberlist_prepare_profile_data($event) {
$user_data = @unserialize(constant('USER_DATA')); //ส่วนนี้จะทำการสร้างตัวแปรที่ได้จาก Event มาใช้งาน
}
บทความที่เกี่ยวข้อง
การสร้าง Extension ใน phpbb
การสร้าง controller สำหรับ phpbb
Event listenner - เขียน Extension บน phpBB 3.1