Joomla包含数据库功能 [英] Joomla include database functions

查看:93
本文介绍了Joomla包含数据库功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Joomla 1.5。我创建了一个自定义组件,将数据完美地从数据库中提取出来。我在我的主要组件文件中初始化数据库,如下所示:

I'm using Joomla 1.5. I have created a custom component that pulls data out of the database perfectly. I initialize the database in my main component file like this:

$db =& JFactory::getDBO();

问题是我的组件页面上有一个jQuery自动完成插件,用于调用PHP文件从我的组件文件夹。该PHP文件在数据库中搜索匹配的结果,但我无法执行查询,因为我无法调用 $ db =& JFactory :: getDBO(); 因为这是一个自定义的PHP页面,我不能在没有任何引用的情况下访问这些函数。

The problem is that I have a jQuery autocomplete plugin on my component page that makes calls to a PHP file from my component folder. That PHP file searches the database for matching results but I can't do the query because I can't call $db =& JFactory::getDBO(); because this is a custom PHP page and I can't access these functions without any references.

任何人都可以帮我在自定义文件中调用Joomla函数吗?

Can anybody help me to call Joomla functions in my custom file ?

谢谢。

推荐答案

我建议不要调用单独的PHP文件,而是使用 raw 视图格式你的组件。为此,请在组件中为jQuery将要提取的数据创建一个视图。为了讨论,我们将调用这个视图 autocomplete 。像任何其他人一样设置 autocomplete 视图,只用 view.raw.php 来代替 view.html.php 。然后在JavaScript中,调用 index.php?option = com_yourcomponent& view = autocomplete& format = raw 。这个HTTP调用只会返回你在视图中输出的内容。

I would recommend not calling a separate PHP file and instead using the raw view format in your component. To do this, create a view in your component for the data that jQuery will be pulling. For discussion, we'll call this view autocomplete. Set up the autocomplete view as you would any other, only using view.raw.php in place of view.html.php. Then in your JavaScript, call index.php?option=com_yourcomponent&view=autocomplete&format=raw. This HTTP call will ONLY return what you output in your view.

如果你绝对必须运行一个外部PHP文件,那么看看如何创建一个独立的应用程序的Joomla!框架: http://docs.joomla.org/How_to_create_a_stand-alone_application_using_the_Joomla%21_Framework This是足够的代码来引入 JFactory 和数据库连接。但是只有在你真的需要时才使用它:否则,你只是在Joomla创建另一个入口点!应用程序,你将不得不维护和保护。

If you absolutely must run an external PHP file, take a look at creating a stand-alone application using the Joomla! Framework: http://docs.joomla.org/How_to_create_a_stand-alone_application_using_the_Joomla%21_Framework This is enough code to pull in JFactory and the database connection. But only use this if you really need to: otherwise, you are just creating another entry point into the Joomla! application that you will have to maintain and secure.

你可能会发现路易斯兰德里的做JSON的帖子很有帮助: http://groups.google.com/group/joomla-dev-cms/browse_thread/thread/5ac0b49c0f458b1a

You may find Louis Landry's post on doing JSON helpful: http://groups.google.com/group/joomla-dev-cms/browse_thread/thread/5ac0b49c0f458b1a

我最近也在博客上介绍了这个话题: http://www.designvsdevelop.com/the-way-not-to-do-javascript-in-joomla/

I also blogged about this topic recently: http://www.designvsdevelop.com/the-way-not-to-do-javascript-in-joomla/

这篇关于Joomla包含数据库功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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