未找到 JFactory [英] JFactory not found

查看:31
本文介绍了未找到 JFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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>";
?>

并使用位于 administrator/components/com_virtuemart/views/product/tpl/product_edit_information.php 的 ajax 从 product_edit_information.php 调用它

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"C:xampphtdocsc22administratorgetuser.php 第 3 行

Fatal error: Class 'JFactory' not found in C:xampphtdocsc22administratorgetuser.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"];//输出7745和7746

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

但是在 jFactory not found 之后发生了错误

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 路径.
受限访问问题用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆