致命错误:在joomla 3.3中找不到类'JFactory'

时间:2014-05-08 14:04:25

标签: php joomla

3 我有一个我在我的网站上开发但没有joomla结构的表单。 在表单上,​​我试图像这样调用活动用户数据:

$user = JFactory::getUser();
echo "<p>Your name is {$user->name}, your email is {$user->email}, and your username is  {$user->username}</p>";

但我得到了: 致命错误:第38行的/home5/onlinepc/public_html/action/subs/custompcorder.php中找不到“JFactory”类

custompcorder.php是我创建的表单的名称,第38行是$ user = JFactory :: getUser(); 我的客人我必须在我的档案中加入一些内容吗?

1 个答案:

答案 0 :(得分:7)

您需要导入Joomla库才能使用它的API,如下所示:

<?php
    define('_JEXEC', 1);
    define('JPATH_BASE', realpath(dirname(__FILE__) . '/../../'));  
    require_once JPATH_BASE . '/includes/defines.php';
    require_once JPATH_BASE . '/includes/framework.php';

    $mainframe = JFactory::getApplication('site');
?>

您可能需要更改上面代码第2行的路径,具体取决于Joomla相对于自定义PHP文件的位置。

相关问题