简体   繁体   English

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

[英]Fatal error: Class 'JFactory' not found in joomla 3.3

3 I have a form I developed on my site but out of joomla structure. 3我有一个我在我的网站上开发的表格但是没有joomla结构。 on the form, I am trying to call active user data like so: 在表单上,​​我试图调用活动用户数据,如下所示:

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

but I am getting: Fatal error: Class 'JFactory' not found in /home5/onlinepc/public_html/action/subs/custompcorder.php on line 38 但我得到:致命错误:第38行/home5/onlinepc/public_html/action/subs/custompcorder.php中找不到类'JFactory'

custompcorder.php is the name of the form I created line 38 is $user = JFactory::getUser(); custompcorder.php是我创建的表单的名称,第38行是$ user = JFactory :: getUser(); I guest I have to include something on my file? 我的客人我必须在我的档案中加入一些东西吗?

You need to import the Joomla library to be able to use it's API, like so: 您需要导入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');
?>

You may need to change the path on line 2 of the code above depending on where Joomla is located in relation to your custom PHP file. 您可能需要更改上面代码第2行的路径,具体取决于Joomla相对于自定义PHP文件的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM