Fatal error: Class 'JFactory' not found in joomla 3.3

假如想象 提交于 2020-08-05 05:28:32

问题


3 I have a form I developed on my site but out of joomla structure. 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

custompcorder.php is the name of the form I created line 38 is $user = JFactory::getUser(); I guest I have to include something on my file?


回答1:


You need to import the Joomla library to be able to use it's API, like so:

<?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.



来源:https://stackoverflow.com/questions/23544091/fatal-error-class-jfactory-not-found-in-joomla-3-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!