php - Where should I initialize session library in CodeIgniter? -
first off, i've checked if there similar question , there appears not be. please let me know if i'm re-asking answered question. thanks.
i'm new codeigniter , not know initialize session library $this->load->library('session');
.
should make controler session in this example? or should put in 1 of existing controlers?
thus far 2 main controlers called pages , user. here part of code each.
user:
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); //login / inscription handler class user extends ci_controller{ public function __construct(){ parent::__construct(); $this->load->database(); $this->load->library('layout'); //$this->load->library('session'); logically load library $this->layout->set_title('user'); } public function add(){ $this->load->model('/user/add'); $this->add->user(); $this->layout->add_includes('css', 'assets/css/success.css'); $this->layout->view('pages/success'); } public function connexion(){ $this->load->model('/user/connexion'); $user = $this->connexion->find(); $newdata = array( ); $this->layout->view('pages/logged'); } } ?>
pages:
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class pages extends ci_controller { public function __construct() { parent::__construct(); // load library $this->load->library('layout'); //$this->load->library('session') or should put here? $this->layout->set_title('pages'); } public function index() { $this->layout->set_title('welcome' . $this->layout->title_separator . 'pages'); $this->layout->add_includes('css', 'assets/css/home.css'); $this->layout->view('pages/home'); } public function contact() { $this->layout->add_includes('css', 'assets/css/contact.css'); $this->layout->view('pages/contact'); } public function nouveautes() { $this->layout->add_includes('css', 'assets/css/news.css'); $this->layout->view('pages/news'); } public function connexion() { $this->layout->view('pages/sign_in'); } public function bureau() { $this->layout->add_includes('css', 'assets/css/board.css'); $this->layout->view('pages/board'); } public function membres() { $this->layout->add_includes('css', 'assets/css/members.css'); $this->layout->view('pages/members'); } }
so, breaking down. pages controler pretty loads main pages. user controler checks if user trying sign or sign in , load page saying "congratulations logged in" (or not).
notice in __consruct() of each controler commented area of think should load library.
where should initialize it? what's used method? why?
additional information:
what want session information? whenever user accesses website (logged in or not) session created. when user logs in update session information.
as want session created if user logged in, or not why not use autoloader (./application/config/autoload.php)?
$autoload['libraries'] = array('session');
this allow access session throughout application.
Comments
Post a Comment