3我有一个我在我的网站上开发的表格但是没有joomla结构.在表单上,我试图调用活动用户数据,如下所示:
$user = JFactory::getUser();
echo "<p>Your name is {$user->name}, your email is {$user->email}, and your username is {$user->username}</p>";
Run Code Online (Sandbox Code Playgroud)
但我得到:致命错误:第38行/home5/onlinepc/public_html/action/subs/custompcorder.php中找不到类'JFactory'
custompcorder.php是我创建的表单的名称,第38行是$ user = JFactory :: getUser(); 我的客人我必须在我的档案中加入一些东西吗?
Lod*_*der 10
您需要导入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');
?>
Run Code Online (Sandbox Code Playgroud)
您可能需要更改上面代码第2行的路径,具体取决于Joomla相对于自定义PHP文件的位置.