2015-10-15 65 views

回答

1

首先你的php頁面必須包含joomla框架,否則你將無法使用任何joomla函數。

我通常在PHP文件開始使用此代碼段(PHP文件是在根目錄):

define('_JEXEC', 1); 

define('JPATH_BASE', './'); //config this as you need 

define('DS', DIRECTORY_SEPARATOR); 
require_once (JPATH_BASE .DS.'includes'.DS.'defines.php'); 
require_once (JPATH_BASE .DS.'includes'.DS.'framework.php'); 

JDEBUG ? $_PROFILER->mark('afterLoad') : null; 
$mainframe =& JFactory::getApplication('site'); 
$mainframe->initialise(); 
JPluginHelper::importPlugin('system'); 
JDEBUG ? $_PROFILER->mark('afterInitialise') : null; 
$mainframe->triggerEvent('onAfterInitialise'); 

// Get user 
$user = JFactory::getUser(); 
if ($user->authorise('core.admin')) { 
//your code here 

} 

請記住,這不是一個正確的解決方案,您應該創建一個組件joomla來擴展它。自定義PHP頁面可能會造成安全問題。

希望它有幫助, Marco