简体   繁体   English

找不到JFactory

[英]JFactory not found

I made a external file in Joomla getuser.php and place it at administrator/getuser.php 我在Joomla getuser.php了一个外部文件,并将其放置在administrator/getuser.php

contain db queries 包含数据库查询

<?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 并使用位于管理员/组件/com_virtuemart/views/product/tpl/product_edit_information.php中的ajax从product_edit_information.php进行调用

code is 代码是

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

error is 错误是

Fatal error: Class 'JFactory' not found in C:\\xampp\\htdocs\\bc22\\administrator\\getuser.php on line 3 致命错误:在第3行的C:\\ xampp \\ htdocs \\ bc22 \\ administrator \\ getuser.php中找不到类'JFactory'

what is the reason of this error how i add external files in joomla 这个错误的原因是什么,我如何在joomla中添加外部文件

i also go through this but cant understand... http://docs.joomla.org/Adding_AJAX_to_your_component 我也经历了这一点,但无法理解... http://docs.joomla.org/Adding_AJAX_to_your_component

defined('_JEXEC') or die('Restricted access'); 

when i put this at top of getuser.php it will give me error 当我把它放在getuser.php的顶部时,它将给我错误

Restricted access 禁止进入

when i echo $q=$_GET["q"]; // output 7745 and 7746 当我echo $q=$_GET["q"]; // output 7745 and 7746 echo $q=$_GET["q"]; // output 7745 and 7746

 <option value="7745">YA Ali</option>
 <option value="7746">Qasim</option>

but after jFactory not found error occurred 但是在找不到jFactory之后发生错误

Sorry for my poor English 对不起,我英语不好

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';

the problem is that you don't include Joomla framework and using JFactory. 问题是您不包括Joomla框架和使用JFactory。 If any function contains error, you should include Joomla path for that function. 如果任何函数包含错误,则应包括该函数的Joomla路径。
Restricted access problem solved with define('_JEXEC', 1); 使用define('_JEXEC', 1);解决了Restricted access问题define('_JEXEC', 1);

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

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