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

[eluser]dec0de[/eluser]
In my code. I have used a one common template file like this
index of products controller

Code:
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

Code:
class MY_Controller extends CI_Controller{

function __construct(){
  parent::__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

Code:
function login(){
  $data['error'] = 0;
  if($this->input->post()){
   $username = $this->input->post('username');
   $password = $this->input->post('password');
   $res = $this->users_m->loginUsers($username,$password);
   if($res){
    $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
      );
     $this->session->set_userdata($sess);
     redirect('dashbord','location');
    }
    return true;
   }else{
    $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


Messages In This Thread
Session Handling (help) - by El Forum - 07-18-2012, 05:33 AM
Session Handling (help) - by El Forum - 07-18-2012, 08:38 AM
Session Handling (help) - by El Forum - 07-18-2012, 09:20 AM
Session Handling (help) - by El Forum - 07-18-2012, 09:24 AM
Session Handling (help) - by El Forum - 07-18-2012, 02:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB