วิธีการกำหนด JPATH_BASE ในปลั๊กอิน
การสร้าง plugin เองเข้าไปใช้ใน Joomla จะพบปัญหาการอ้างถึง path ของไฟล์ระบบ joomla
ลองมาดูวิธีการแก้ไขกัน
เพิ่ม Code ลงไปส่วนบนของไฟล์ที่ต้องการเรียกใช้งานผ่าน joomla
//Load Joomla environment
if (! defined('_JEXEC'))
define('_JEXEC', 1);
$DS=DIRECTORY_SEPARATOR;
define('DS', $DS);
//Get component path
preg_match("/\\{$DS}components\\{$DS}com_.*?\\{$DS}/", __FILE__, $matches, PREG_OFFSET_CAPTURE);
$component_path = substr(__FILE__, 0, strlen($matches[0][0]) + $matches[0][1]);
define('JPATH_COMPONENT', $component_path);
define('JPATH_BASE', substr(__FILE__, 0, strpos(__FILE__, DS.'components'.DS) ));
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once JPATH_BASE .DS.'includes'.DS.'framework.php';
jimport( 'joomla.environment.request' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
// ทดสอบการส่งค่า
$session =& JFactory::getSession();
$session->set('name','ค่าที่ต้องก่าร'); //Set session name and value
echo $session->get('name'); //Get session value
Cr: http://stackoverflow.com/questions/6981023/how-to-define-jpath-base-in-a-plugin
|
แนะนำการใช้งาน หัวข้ออื่นๆ
|
contentbiz บน Facebook
เพิ่มความมั่นใจให้กับคุณ

|