【问题标题】:Codeigniter HMVC + ion_auth trouble loading the config itemsCodeigniter HMVC + ion_auth 无法加载配置项
【发布时间】:2016-02-24 16:56:56
【问题描述】:

我已经敲了 5 个小时的头,终于解决了问题,但我就是在不知道原因的情况下无法入睡。让我先解释一下这个问题。

我使用了 codeigniter HMVC 扩展并将 ion_auth 作为单独的模块安装。

|-modules
|--auth
|---config
|-----ion_auth.php
|---controllers
|-----auth.php
|---models
|-----ion_auth_model.php
|---views

当我尝试获取用户组时,我开始遇到连线 SQL 错误。然后我缩小了问题范围,发现config/ion_auth.php 中的项目没有加载到ion_auth_model.php 文件中。

ERROR - 2016-02-24 20:09:26 --> 查询错误:您的 SQL 语法;检查与您的 MySQL 服务器相对应的手册 在 'as id, .name, 附近使用正确语法的版本 .description 加入 .=.id 在哪里。 = '2'' 在第 1 行 - 无效 查询:选择。如id、.name、.description 加入 .=.id 在哪里 。 ='2'

然后我尝试了一些东西,当我从中删除索引 'ion_auth' ion_auth_model.php 中的几个方法调用一切都开始工作了。

我变了

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

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

谁能告诉我为什么它有效?

【问题讨论】:

  • 在 Ion Auth 模型的构造函数中,是否按如下方式加载了 ion_auth 配置: $this->load->config('auth/ion_auth', TRUE);
  • 是的。就是这样加载的

标签: codeigniter hmvc codeigniter-hmvc


【解决方案1】:

这是文件system\core\Config.php中CodeIgniter函数config->item()的内部实现

/**
 * 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参数时,函数会检查两个参数是否在config中初始化,并返回CI实例的config[$index];或 null 如果其中任何一个未初始化。

如果在 CI 实例中未设置 config[$item],该函数将始终返回 null。假设情况并非如此,因为避免$index 时您的通话不会崩溃。

所以当您将$index 作为第二个参数传递时,您的代码会因为函数返回null 而崩溃,这意味着CI 实例的config[$index] 未设置。现在的问题是为什么它没有设置,我在这里帮不了你,但看起来你缺少加载一些模块。

最好的问候

【讨论】:

    猜你喜欢
    • 2013-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多