• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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

#2
[eluser]dec0de[/eluser]
bump (help)

#3
[eluser]john_j[/eluser]
Maybe session class can help you.

http://ellislab.com/codeigniter/user-gui...sions.html

#4
[eluser]dec0de[/eluser]
[quote author="john_j" date="1342628437"]Maybe session class can help you.

http://ellislab.com/codeigniter/user-gui...sions.html[/quote]

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

#5
[eluser]Aken[/eluser]
See $this->load->vars()


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.