【问题标题】:JFactory not found未找到 JFactory
【发布时间】:2012-12-16 08:17:24
【问题描述】:

我在 Joomla getuser.php 中制作了一个外部文件并将其放在 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 调用它

代码是

<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:\xampp\htdocs\bc22\administrator\getuser.php 在第 3 行

这个错误的原因是什么 我如何在 joomla 中添加外部文件

我也经历过这个,但无法理解...... http://docs.joomla.org/Adding_AJAX_to_your_component

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

当我把它放在 getuser.php 的顶部时,它会给我错误

访问受限

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

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

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

对不起我的英语不好

【问题讨论】:

    标签: php ajax joomla


    【解决方案1】:

    您应该在代码顶部添加此代码:

    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); 解决

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 2012-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-04
      • 2015-12-22
      相关资源
      最近更新 更多