使用Ajax查询的Joomla组件开发组件、Ajax、Joomla

2023-09-11 22:29:01 作者:我比想象中爱你

我用AJAX查询的PHP脚本,但我希望他们能够的Joomla的(2.5)框架的框架下进行操作,所以我可以有会话ID的,用户ID等提供给我。

I have a PHP script used for AJAX queries, but I want them to be able to operate under the umbrella of Joomla's (2.5) framework so I can have session id's, user id's etc available to me.

例如:

$(function () {
 $.ajax({                                     
   url: 'ajax.php',   //the script to call to get data                     
   dataType: 'json'        //data format     
   ...
 });
}); 

在哪里ajax.php有code,如:

Where ajax.php has code such as:

$user =& JFactory::getUser();

据我所知这是最好的让你的AJAX / JSON调用一个标准的Joomla组件。我不知道很多关于发展的MVC组成部分,但是从我所看到的却是矫枉过正的方式为我想做的事情。

From what I understand it's best to make your AJAX/JSON calls to a standard Joomla component. I don't know much about developing a MVC component but from what I can see it is way overkill for what I want to do.

有没有别的东西,我可以用?

Is there something else I could be using?

推荐答案

如果您创建一个组件,您可以创建新的视图对原材料查询,例如元件库/ com_yourcomponent /视图/ AJAX / view.raw.php ,并把所有的逻辑和输出在那里 网址为的index.php选项= com_yourcomponent和放大器;查看= AJAX和放大器;格式=原

if you create a component you can create new view for raw queries for example compoments/com_yourcomponent/views/ajax/view.raw.php and put all logic and output in there url will be index.php?option=com_yourcomponent&view=ajax&format=raw

您可以用创建 Controller.php这样新的方法退出()打印信息和网址后,将的index.php选项= com_yourcomponent和放大器;任务= AJAX

you can to create new method in controller.php with exit() after print information and url will be index.php?option=com_yourcomponent&task=ajax