I have been banging my head for 5 hours and I finally solved the problem but I just cannot go to sleep without knowing the reason. Let me explain the issue first.
I have used codeigniter HMVC extension and installed ion_auth as a separate module.
|-modules
|--auth
|---config
|-----ion_auth.php
|---controllers
|-----auth.php
|---models
|-----ion_auth_model.php
|---views
When I was trying to get a user's group I started to get wired SQL errors. Then I narrowed the issue and figured out that the items in config/ion_auth.php
were not loaded in the ion_auth_model.php
file.
ERROR - 2016-02-24 20:09:26 --> Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as
id
, .name
, .description
JOIN ON .=.id
WHERE . = '2'' at line 1 - Invalid query: SELECT . asid
, .name
, .description
JOIN ON .=.id
WHERE . = '2'
Then I tried couple of stuffs and when I remove the index 'ion_auth'
from
couple of method calls in ion_auth_model.php
everything started to work.
I changed
$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');
Can anyone tell me why it worked?
This is the inner implementation of the CodeIgniter function config->item() found in the file system\core\Config.php
When you pass the
$index
parameter, the function checks if both parameters are initialized in the config and returnsconfig[$index]
of the CI instance; ornull
if any of them is not initialized.If
config[$item]
is not set in the CI instance, the function returns alwaysnull
. Let's assume this is not the case, as your call don't crash when avoiding$index
.So when you pass
$index
as the second parameter, your code crashes because the function returnsnull
, and that means that theconfig[$index]
of the CI instance is not set. Now the question is why it's not set, and I can't help you here, but it looks like you are missing to load some modules.Best regards