找不到JFactory [英] JFactory not found
问题描述
我在Joomla getuser.php
中制作了一个外部文件,并将其放置在administrator/getuser.php
I made a external file in Joomla getuser.php
and place it at administrator/getuser.php
包含数据库查询
<?php
$q=$_GET["q"];
$db = JFactory::getDBO();
// Create a new query object.
$query = $db->getQuery(true);
$query->select($db->nameQuote('product_name'));
$query->from('#__virtuemart_products_en_gb');
$query->where($db->nameQuote('virtuemart_product_id').' = '.$db->quote($q));
$db->setQuery($query);
$result = $db->loadResult();
echo "<tr>";
echo "<td>" . $result['product_name'] . "</td>";
echo "</tr>";
?>
并使用
and call it from product_edit_information.php
using ajax located at administrator/components/com_virtuemart/views/product/tpl/product_edit_information.php
代码为
<form>
<select name="users" onChange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="7745">YA Ali</option>
<option value="7746">Qasim</option>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>
<script>
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
错误是
致命错误:找不到类'JFactory' 第3行上的C:\ xampp \ htdocs \ bc22 \ administrator \ getuser.php
Fatal error: Class 'JFactory' not found in C:\xampp\htdocs\bc22\administrator\getuser.php on line 3
此错误的原因是什么 我如何在joomla中添加外部文件
what is the reason of this error how i add external files in joomla
我也经历了这个,但无法理解... http://docs.joomla.org/Adding_AJAX_to_your_component
i also go through this but cant understand... http://docs.joomla.org/Adding_AJAX_to_your_component
defined('_JEXEC') or die('Restricted access');
当我把它放在getuser.php的顶部时,它将给我错误
when i put this at top of getuser.php it will give me error
访问受限
当我echo $q=$_GET["q"]; // output 7745 and 7746
<option value="7745">YA Ali</option>
<option value="7746">Qasim</option>
但是在未找到jFactory之后发生错误
but after jFactory not found error occurred
对不起,我的英语不好
推荐答案
您应将此代码添加到代码顶部:
you should add this code in top of your code:
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
if (file_exists(dirname(__FILE__) . '/defines.php')) {
include_once dirname(__FILE__) . '/defines.php';
}
if (!defined('_JDEFINES')) {
define('JPATH_BASE', dirname(__FILE__));
require_once JPATH_BASE.'/includes/defines.php';
}
require_once JPATH_BASE.'/includes/framework.php';
require_once JPATH_BASE.'/includes/helper.php';
require_once JPATH_BASE.'/includes/toolbar.php';
问题在于您不包括Joomla框架,也不使用JFactory.如果任何函数包含错误,则应包括该函数的Joomla路径.
Restricted access
问题已通过define('_JEXEC', 1);
the problem is that you don't include Joomla framework and using JFactory. If any function contains error, you should include Joomla path for that function.
Restricted access
problem solved with define('_JEXEC', 1);
这篇关于找不到JFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!