How to Session variable pass one controller to another controller using codeigniter

kishankakadiya
I have Two Controller.

1.Login Controller
2. NewsLine Controller

Login Controller Below Code:

$query = $this->login_model->select_login($_POST);
            if ($query) {
                $user = array(
                    'uname' => $query['uname'],
                    'pwd' => $query['pwd']
                );
                $this->session->set_userdata($user);
                $_SESSION['id'] = $user['id'];
                redirect('Newsline');
            }

My Question is How To $_SESSION['id] pass to Newsline Controller

Alok Patel

As mentioned in CodeIgniter documentation to set the session data you an do following,

$newdata = array(
         'username'  => 'uname',
         'email'     => '[email protected]'
);

$this->session->set_userdata($newdata);

Now this is how you an retrive the data,

$session_id = $this->session->userdata('email');

In your case your code should look like this,

if ($query) {
   $user = array(
         'uname' => $query['uname'],
         'pwd' => $query['pwd'],
         'id' => $query['id']
   );
   $this->session->set_userdata($user);
   redirect('Newsline');
}

To retrive ID on NewsLine controller,

$session_id = $this->session->userdata('id');

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to Session variable pass one controller to another controller using codeigniter

From Dev

how to pass an array from one class controller to another in codeigniter

From Dev

How to Pass variable to another page using Angular controller?

From Dev

How to call one controller function in another controller in codeigniter

From Dev

How to load more than one controller in another controller in CodeIgniter

From Dev

How to call one controller function in another controller in codeigniter

From Dev

How to pass Response from one controller to another?

From Dev

How do i access/pass variable from another view controller? It's not the next view controller, but the view controller after the next one in Swift

From Dev

Using a DbContext variable from one Controller to Another

From Dev

How to pass a value from one controller to another controller in laravel

From Dev

how to pass list of objects from one controller to another controller?

From Dev

How to pass data from one controller to another controller in my case

From Dev

How to pass a value from one controller to another controller in laravel

From Dev

how to pass object data from one controller to another controller in angularjs

From Dev

how to save session value and pass it from one function of controller to another function

From Dev

Codeigniter: passing a post variable from one function to another in a controller

From Dev

Pass php variable from view to controller to model using codeigniter

From Dev

Pass variable from one controller to another laravel 5.4

From Dev

How to call a controller from another controller in codeigniter?

From Dev

Accessing one controller variable in another controller in Rails

From Dev

How to inject one controller function to another controller using angularjs?

From Dev

How to pass a value of a variable from view to controller in codeigniter

From Dev

How to pass variable serialize through ajax to codeigniter controller?

From Dev

How to bring data from model to controller to use in session using codeigniter

From Dev

How to pass data from one view controller to another view controller which is embedded in navigation controller

From Dev

how to pass data from one view controller to another and between the view controller there is a reveal view controller

From Dev

How to redirect to another controller in CodeIgniter?

From Dev

Unable to pass variable from codeigniter controller to the view?

From Dev

passing values from One controller to another Controller using Session or TempData not working?

Related Related

  1. 1

    How to Session variable pass one controller to another controller using codeigniter

  2. 2

    how to pass an array from one class controller to another in codeigniter

  3. 3

    How to Pass variable to another page using Angular controller?

  4. 4

    How to call one controller function in another controller in codeigniter

  5. 5

    How to load more than one controller in another controller in CodeIgniter

  6. 6

    How to call one controller function in another controller in codeigniter

  7. 7

    How to pass Response from one controller to another?

  8. 8

    How do i access/pass variable from another view controller? It's not the next view controller, but the view controller after the next one in Swift

  9. 9

    Using a DbContext variable from one Controller to Another

  10. 10

    How to pass a value from one controller to another controller in laravel

  11. 11

    how to pass list of objects from one controller to another controller?

  12. 12

    How to pass data from one controller to another controller in my case

  13. 13

    How to pass a value from one controller to another controller in laravel

  14. 14

    how to pass object data from one controller to another controller in angularjs

  15. 15

    how to save session value and pass it from one function of controller to another function

  16. 16

    Codeigniter: passing a post variable from one function to another in a controller

  17. 17

    Pass php variable from view to controller to model using codeigniter

  18. 18

    Pass variable from one controller to another laravel 5.4

  19. 19

    How to call a controller from another controller in codeigniter?

  20. 20

    Accessing one controller variable in another controller in Rails

  21. 21

    How to inject one controller function to another controller using angularjs?

  22. 22

    How to pass a value of a variable from view to controller in codeigniter

  23. 23

    How to pass variable serialize through ajax to codeigniter controller?

  24. 24

    How to bring data from model to controller to use in session using codeigniter

  25. 25

    How to pass data from one view controller to another view controller which is embedded in navigation controller

  26. 26

    how to pass data from one view controller to another and between the view controller there is a reveal view controller

  27. 27

    How to redirect to another controller in CodeIgniter?

  28. 28

    Unable to pass variable from codeigniter controller to the view?

  29. 29

    passing values from One controller to another Controller using Session or TempData not working?

HotTag

Archive