从任何其他目录获取joomla中的文件路径

时间:2013-07-31 05:08:16

标签: php joomla

我正在研究joomla模块,但面临一些问题。我创建了7个以上的模块,每个模块都有dbcon.php文件,其中包含与db代码的连接。现在的问题是让我们假设我更改密码所以现在我必须在每个模块中的每个dbcon.php文件中更改密码,这是不正确的方法。我想要做的是为每个模块放置一个通用的dbcon.php文件,并在每个模块中包含该文件,这样当我需要更改凭据时,我必须为每个自定义模块查找一次dbcon.php文件。

所以为了这个目的,我把dbcon.php文件放在modules文件夹中,然后尝试获取那个文件

  include( JURI::base().'modules/dbcon.php');

让我回到那条路径

  http://localhost/Jmd_tests/modules/dbcon.php

这是正确的,但它给了我警告,模块无效。

这是警告信息

 Warning: include() [<a href='function.include'>function.include</a>]: http:// wrapper is disabled in the server configuration by allow_url_include=0 in C:\wamp\www\Jmd_tests\modules\mod_stune_cat_indians\helper.php on line 74

 Warning: include(http://localhost/Jmd_tests/modules/dbcon.php) [<a href='function.include'>function.include</a>]: failed to open stream: no suitable wrapper could be found in C:\wamp\www\Jmd_tests\modules\mod_stune_cat_indians\helper.php on line 74

 Warning: include() [<a href='function.include'>function.include</a>]: Failed opening 'http://localhost/Jmd_tests/modules/dbcon.php' for inclusion (include_path='.;C:\php\pear') in C:\wamp\www\Jmd_tests\modules\mod_stune_cat_indians\helper.php on line 74

所以现在我被困在这里,不知道该怎么做才能得到正确的结果。我将非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

首先,您需要在模块中使用db文件吗?

使用joomla默认Db对象而不是文件include。

如下所示。

$db = JFactory::getDBO();
$db->setQuery('your mysql query');
$db->query();
$res = $db->loadAssocList();//for multiple rows only single row use $db->loadAssoc();

echo "<pre/>";
print_r($res);

这应该是模块助手中的一个函数。

获取正确的路径使用方法。 JURI::root()将返回http://yourdomain.com/

JPATH_SITE将返回upto / public_html,这是必需的。

希望它能解决你的问题。

相关问题