How to get parameter value in controller called using redirect function in codeigniter

9.5k views Asked by At

I have started with codeingniter, I am calling controller using redirect() function with parameter, how can I get the parameter value in controller.php?

view.php

$para array(
             'id'=>$id, 'name'=>$name
);

redirect('login_controller/get_permissions/'.$para);    

I need $para value in controller.php, how can I get value of $para?

login_controller.php

   class Login_controller extends CI_Controller
   {
        function __construct()
        {
            parent::__construct();
        }

        function get_permission()
        {
            $get_para = $_GET['para'];
            echo $get_para;
        }
    }

it's not working :(

3

There are 3 answers

0
codeBYmahesh On BEST ANSWER

I have replaced this code:

$para array(
         'id'=>$id, 'name'=>$name
  );
 $this->session->set_flashdata('para',$para);

redirect('login_controller/get_permissions); 

to

    $CI = get_instance();
    $CI->load->library('session');

    $para array(
             'id'=>$id, 'name'=>$name
      );

    $CI->session->set_flashdata('para',$para);

    redirect('login_controller/get_permissions); 

Its working now...

1
Nabin Kunwar On
    $id='vlaue';
    $name='name';    
    redirect('login_controller/get_permissions/'.$id.'/'.$name);  

and then

    function get_permission($id,$name)
      {
          echo $id;
         echo $name;
      }

But If you want to send array then set_flash Data would be good

$para array(
         'id'=>$id, 'name'=>$name
  );
 $this->session->set_flashdata('para',$para);

redirect('login_controller/get_permissions);  

And then

    function get_permission()
      {
         print_r( $this->session->flashdata('para'));
      }

See more Here

1
user2936213 On

Use this:

function get_permission($para)
    {
        print_r($para);
    }