문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top