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


get file path in joomla from any other directory

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

所以为了这个目的,我把dbcon.php文件放在模块文件夹里,然后试着得到像一样的文件

  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

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

首先,为什么您的模块中需要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将返回高达/public_html,这是必需的。

希望它能解决你的问题。