Welcome Guest, Not a member yet? Register   Sign In
Session Handling (help)

In my code. I have used a one common template file like this
index of products controller

function index($page = "/products/products"){
  $data['title'] = "Products"; // Title of the page
  $data['plist'] = $this->products_m->listProducts(); // list of the avaible products from the Database
  $data['page'] = $page;
  $this->load->view('template', $data); //Default layout data entering

the problem I'm having I need to view my loggedin users user name . Im using a My_Controller like I've mentioned below

class MY_Controller extends CI_Controller{

function __construct(){
  $this->data['user'] = $this->session->all_userdata();
  if (empty($this->data['user']['logged_in'])){
   redirect('users/login', 'location');  
  //print_r($this->data['user']['user_name']); // Username of the logged user

Users Controller login method

function login(){
  $data['error'] = 0;
   $username = $this->input->post('username');
   $password = $this->input->post('password');
   $res = $this->users_m->loginUsers($username,$password);
    $sess = array();
    foreach ($res as $row) {
     $sess = array(
      'id' => $row->user_id,
      'user_name' => $row->user_name,
      'user_group' => $row->user_group,
      'logged_in' => TRUE
    return true;
    $data['error'] = 1;

I was wondering how can I use username of the user in every page without mentioning this in every method in every controller . doing a $this->load->view in this __construct() will do , but it will miss place the interface of the template

please help

bump (help)

Maybe session class can help you.


[quote author="john_j" date="1342628437"]Maybe session class can help you.


I'm sorry I know how to display session values . the problem is how can I make it in every page . because like I mentioned before I'm setting template variables on each method . I dont want to set the session user_name on every method . Sad

See $this->load->vars()

Theme © iAndrew 2016 - Forum software by © MyBB