Codeigniter HMVC + ion_auth 配置项加载问题

9
我已经苦思冥想了五个小时,终于解决了问题,但是我不想在不知道原因的情况下就去睡觉。让我先解释一下问题。
我使用了CodeIgniter HMVC扩展,并将ion_auth作为单独的模块安装。
|-modules
|--auth
|---config
|-----ion_auth.php
|---controllers
|-----auth.php
|---models
|-----ion_auth_model.php
|---views

当我尝试获取一个用户组时,出现了一些奇怪的SQL错误。然后我缩小了问题范围,并发现在ion_auth_model.php文件中没有加载config/ion_auth.php中的项目。

错误-2016年02月24日20:09:26->查询错误:您有一个错误 SQL语法;检查与您的MySQL服务器对应的手册 版本以使用正确的语法 near 'as id, .name, .description JOIN ON .=.id WHERE . = '2'' at line 1 - Invalid query: SELECT . as id, .name, .description JOIN ON .=.id WHERE . = '2'

然后我尝试了几个方法,当我从ion_auth_model.php中的一些方法调用中删除索引'ion_auth'时,一切都开始正常工作。
我改变了
$this->tables  = $this->config->item('tables', 'ion_auth');
$this->join            = $this->config->item('join', 'ion_auth);

to

$this->tables  = $this->config->item('tables');
$this->join            = $this->config->item('join');

有人能告诉我为什么它起作用了吗?


在 Ion Auth 模型的构造函数中,ion_auth 配置是否如下加载:$this->load->config('auth/ion_auth', TRUE); - adarshdec23
是的。它就是这样加载的。 - Fawzan
1个回答

1
这是CodeIgniter函数config->item()的内部实现,可以在文件system\core\Config.php中找到。
/**
 * Fetch a config file item
 *
 * @param   string  $item   Config item name
 * @param   string  $index  Index name
 * @return  string|null The configuration item or NULL if the item doesn't exist
 */
public function item($item, $index = '')
{
    if ($index == '')
    {
        return isset($this->config[$item]) ? $this->config[$item] : NULL;
    }

    return isset($this->config[$index], $this->config[$index][$item]) ? $this->config[$index][$item] : NULL;
}

当您传递$index参数时,该函数会检查配置中是否初始化了两个参数,并返回CI实例的config[$index];如果其中任何一个未初始化,则返回null。
如果在CI实例中没有设置config[$item],则该函数始终返回null。假设这不是问题所在,因为您在避免$index时调用没有崩溃。
因此,当您将$index作为第二个参数传递时,您的代码会崩溃,因为该函数返回null,这意味着CI实例的config[$index]未设置。现在的问题是为什么它未设置,我无法帮助您,但看起来您错过了加载某些模块。
最好的问候

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接