[英]JFactory not found
我在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>";
?>
並使用位於管理員/組件/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>
錯誤是
致命錯誤:在第3行的C:\\ xampp \\ htdocs \\ bc22 \\ administrator \\ getuser.php中找不到類'JFactory'
這個錯誤的原因是什么,我如何在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
echo $q=$_GET["q"]; // output 7745 and 7746
<option value="7745">YA Ali</option>
<option value="7746">Qasim</option>
但是在找不到jFactory之后發生錯誤
對不起,我英語不好
您應該在代碼頂部添加以下代碼:
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);
解決了Restricted access
問題define('_JEXEC', 1);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.