Welcome Guest, Not a member yet? Register   Sign In
Creating ci_sessions table: can I over-ride auto-loading of the session class?
#1

[eluser]aidehua[/eluser]
I have a "single-use" function called create_my_tables() which creates (IF NOT EXISTS) all the database tables for my application.

One of these tables is the table that CodeIgniter uses for session management, ci_sessions.

Problem: I have the Session library auto-loaded, and

Code:
$config['sess_use_database'] = TRUE;

in my config file. The Session library wants to use the ci_sessions table (naturally enough). So I can't run create_my_tables() (or any other function in CodeIgniter) because the ci_sessions table doesn't exist yet. But I can't create ci_sessions because I can't run create_my_tables()... If you see what I mean.

Possible solutions:

Obviously I could create the ci_sessions tables manually.

Or I could switch off auto-loading of the sessions library in my config/autoload file temporarily, just to let me run create_my_tables(), and then turn it back on again.

Both of these are fine, but it would be nicer if I could programmatically over-ride auto-loading of the session library just to run this one create_my_tables() function.

Does anyone have any ideas on whether/how this might be done? (I'm sure I can't be the first person to want to do this - but I couldn't find an answer in the forums or the userguide.)
#2

[eluser]aidehua[/eluser]
Pretty simple solution:

In config.php:
Code:
if ($_SERVER['REQUEST_URI'] == '/admin/create_my_tables'):
    $config['sess_use_database']    = FALSE;
else:
    $config['sess_use_database']    = TRUE;
endif;




Theme © iAndrew 2016 - Forum software by © MyBB