Question

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

Was it helpful?

Solution 3

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...

OTHER TIPS

    $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

Use this:

function get_permission($para)
    {
        print_r($para);
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top