ถามตอบ ปัญหาการพัฒนา Extension ไม่ว่าจะเป็น Module plugin Component หรือ แม้แต่ template การปรับแต่งโค้ด Joomla ต่างๆ ทุกเวอร์ชั่น 1.5 2.5 หรือ 3.x
Moderator: mindphp , ผู้ดูแลกระดาน
Thanapoom1514
PHP VIP Members
โพสต์: 4329 ลงทะเบียนเมื่อ: 04/07/2022 9:46 am
โพสต์ที่ยังไม่ได้อ่าน
โดย Thanapoom1514 » 30/03/2023 4:12 pm
สอบถามการทำ cache เก็บขอมูลกระทู้โดยใช้ curl ในการดึงข้อมูลมาเก็บใน cache ซึ่งผมจะปรับมาใช้ class ของ joomla 3 ครับ ต้อง include ไฟล์ไหนบ้างครับของ joomla 3 ที่จำเป็นต้องใช้ กับใช้ class cache ใช้ฟังก์ชันยังไงบ้างครับ
โดยโค้ด php ที่จะมาปรับมาใช้ class ของตัว joomla 3
โค้ด: เลือกทั้งหมด
$page_post_topic = 1;
if (isset($_GET['p'])) {
$page_post_topic = $_GET['p'];
};
$cache_file = '../cache/' . md5($_SERVER['REQUEST_URI']);
if (file_exists($cache_file) && (time() - filemtime($cache_file)) < 600) {
$data_array = json_decode(file_get_contents($cache_file), true);
} else {
if (file_exists($cache_file) && (time() - filemtime($cache_file)) >= 600) {
$cache_files = glob($cache_file);
foreach ($cache_files as $file) {
if (is_file($file) && (time() - filemtime($file)) >= 600) {
unlink($file);
};
};
};
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $curl_json.'/0/'.$page_post_topic,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
'accept: application/json'
)
));
$json_string = curl_exec($ch);
curl_close($ch);
$data_array = json_decode($json_string, true);
file_put_contents($cache_file, $json_string);
}
Thanapoom1514
PHP VIP Members
โพสต์: 4329 ลงทะเบียนเมื่อ: 04/07/2022 9:46 am
โพสต์ที่ยังไม่ได้อ่าน
โดย Thanapoom1514 » 31/03/2023 11:57 am
ผมปรับใช้ class ของง Joomla 3 ขึ้น error แบบนี้แทนครับ
Joomla Development-1.png (17.16 KiB) Viewed 1135 times
โค้ด: เลือกทั้งหมด
Error: Failed to start application: Failed to start the session because headers have already been sent by
"C:\xampp\htdocs\Joomla_3.10.10\tools\v2_header.php" at line 54.
ซึ่งบรรทัดที่แจ้งในไฟล์ v2_header.php คือ
โค้ด: เลือกทั้งหมด
<a class="hidden-xs" href="<?php echo $word_recent['header'];?>"><img class="logo" src="#" alt="logo"></a>
โค้ดที่ปรับใช้ class cache
โค้ด: เลือกทั้งหมด
define('_JEXEC', 1);
define('JPATH_BASE', '../../');
require_once JPATH_BASE . 'includes/defines.php';
require_once JPATH_BASE . 'includes/framework.php';
$application = JFactory::getApplication('site');
$cache = JFactory::getCache('recent_topic');
$cache->setCaching(true);
$cache->setLifeTime(600);
$page_post_topic = 1;
if (isset($_GET['p'])) {
$page_post_topic = $_GET['p'];
};
$cache_file = md5($_SERVER['REQUEST_URI']);
if ($cache->get($cache_file, false)) {
$data_array = $cache->get($cache_file, false);
} else {
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $curl_json.'/0/'.$page_post_topic,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
'accept: application/json'
)
));
$json_string = curl_exec($ch);
curl_close($ch);
$data_array = json_decode($json_string, true);
$cache->store($data_array, $cache_file);
}
$cache->clean(false, 'recent_topic');
mindphp
ผู้ดูแลระบบ MindPHP
โพสต์: 41344 ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:
โพสต์ที่ยังไม่ได้อ่าน
โดย mindphp » 31/03/2023 12:27 pm
ถ้าเอาไปใช้งานกับโปรแกรม อื่นแนะนำให้ include ไฟล์ class จะทำใช้เอาไปใช้
ถ้า มา
โค้ด: เลือกทั้งหมด
$application = JFactory::getApplication('site');
หมายถึง จะเราทั้งระบบไปใช้ ทำจะให้โปรแกรมที่เขียนทำงานหนัก
Thanapoom1514
PHP VIP Members
โพสต์: 4329 ลงทะเบียนเมื่อ: 04/07/2022 9:46 am
โพสต์ที่ยังไม่ได้อ่าน
โดย Thanapoom1514 » 31/03/2023 7:30 pm
ครับ ผมได้ลองปรับสามารถบันทึกข้อมูล cache ได้แล้วครับ
โค้ด: เลือกทั้งหมด
define('_JEXEC', 1);
define('JPATH_BASE', '../../');
require_once JPATH_BASE . 'includes/defines.php';
require_once JPATH_BASE . 'includes/framework.php';
$cache = JFactory::getCache('recent_topic','');
$cache->setCaching(true);
$cache->setLifeTime(600);
$page_post_topic = 1;
if (isset($_GET['p'])) {
$page_post_topic = $_GET['p'];
};
$cache_file = md5($_SERVER['REQUEST_URI']);
if ($cache->get($cache_file, false)) {
$data_array = $cache->get($cache_file, false);
} else {
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $curl_json.'/0/'.$page_post_topic,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
'accept: application/json'
)
));
$json_string = curl_exec($ch);
curl_close($ch);
$data_array = json_decode($json_string, true);
$cache->store($data_array, $cache_file);
}
$current_time = time();
if ($current_time % 600 == 0) {
$cache->clean();
}
Joomla Development-1.png (91.88 KiB) Viewed 1087 times
0 ตอบกลับ
571 แสดง
โพสต์ล่าสุด โดย fonfonn
23/11/2022 2:43 pm
0 ตอบกลับ
1213 แสดง
โพสต์ล่าสุด โดย Ittichai_chupol
13/11/2019 6:41 pm
0 ตอบกลับ
4015 แสดง
โพสต์ล่าสุด โดย Ittichai_chupol
28/02/2020 4:39 pm
3 ตอบกลับ
1246 แสดง
โพสต์ล่าสุด โดย tsukasaz
11/10/2022 2:40 pm
1 ตอบกลับ
1316 แสดง
โพสต์ล่าสุด โดย tsukasaz
11/09/2017 11:33 am
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 72