My website uses CI just for the admin part, so structure will look similar to:
-root
sitewideinitfile.php
various other files
admin (folder)
CI Application:
index.php
All my non-CI website files include_once sitewideinitfile.php to have access to global settings like
Code:
$siteVars['debug_mode'] = true;
$siteVars['abspath']= 'absolute/path'
and so on.
I would like to have these variables available in CI as well, however, I am not sure how to do that.
I understand I need to pass the data in views, but still not sure what is the best way to go to have them available in controllers/models.
The admin part of the website cannot be accessed directly (so a user HAS to login in the non-CI part of the website).
What I did/tried so far:
added to index.php:
PHP Code:
session_start();
include_once('../sitewideinitfile.php');
$_SESSION['siteVars'] = $siteVars;
in each controller:
Code:
function __construct() {
$this->load->library('php_session');
$this->php_session->start();
}
$data['siteVars'] = $this->php_session->get('siteVars');
$this->load->view('viewname', $data);
Questions:
1) Is it good practice to pass data around using $_SESSION? I don't really like it, I would rather have them loaded from file like it happens in the non-admin (non-CI) area of the website
2) Is it good practice to add those lines to 'index.php' file?
3) Is it good practice to start the session this way (and in that location, again index.php)?
4) Is the controller code above the right way to go?
So far, this approach seems to get the job done, but I didn't test a lot yet.
Thank you!