找不到类"JFactory" [英] Class 'JFactory' not found

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

问题描述

我一直在使用Jumi在Joomla中创建一些模块.因此,我可以编写任何php/javascript代码并创建一个Jumi模块,该模块可以显示在我想要的位置.

I've been creating some modules in Joomla using Jumi. So I can write any php/javascript code and create a Jumi module that I can display where I want.

我这样做已经有一段时间了,但是现在我正在尝试使用Jquery进行一些AJAX开发,但是出现了这个错误:

I've been doing this for a while without problems but now that I'm trying some AJAX development with Jquery I'm getting this error:

Class 'JFactory' not found in api.php

所以我有一个带有jQuery代码的PHP文件:

So I have a PHP file with the jQuery code:

$(function() {
    $.ajax({
        url: 'ajax_dashboard/api.php',                  //the script to call to get data
        data: "",
        dataType: 'json',                //data format
        success: function(data)          //on recieve of reply
        {
            var id = data[0];              //get id
            var vname = data[1];           //get name

            $('#output').append("<b>id: </b>"+id+"<b> name: </b>"+vname)
                .append("<hr />"); //Set output element html
        }
    });
});

如您所见,它调用api.php脚本进行一些服务器处理.该文件有许多joomla调用,例如:

As you can see it calls the api.php script to do some server processing. This file has a number of joomla calls like:

$user = &JFactory::getUser();

那么为什么在这种情况下我没有Joomla框架可用?

So why in this case do I not have the Joomla framework available?

推荐答案

问题是您的Ajax调用最终出现在Joomla平台"之外的文件中.如果可能的话,正确的方法是使ajax调用类似以下内容:

The problem is that your Ajax call ends up in a file out of the Joomla "platform". The proper way to do that, if possible, is to make the ajax call something like:

index.php?option = yourcomponent& controller = xxx& task = yyy

index.php?option=yourcomponent&controller=xxx&task=yyy

(这意味着您应该在该组件内部拥有一个组件"mycomponent"和一个控制器"xxx") 然后,控制器应负责处理ajax调用并发送响应.例如,您可以返回json编码的响应,也可以返回所需的任何信息.

(it means you should have a component "mycomponent" and a controller "xxx" inside that component ) Then the controller should be responsible to handle the ajax call and send a response. You can return json-encoded response for example or anything you need.

我希望它能帮助

这篇关于找不到类"JFactory"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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