Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to sent parameter in redirect - php codeigniter

the following code gives me an error. I want to call a function and pass a parameter to it with php codeigniter.

redirect(base_url() . 'MainController/Student_Login($user_email)')

here MainController is the Controller name, Student_Login is the function $user_email is a variable that holds the user email id. I have also tried sending it through url. e.g.

redirect(base_url() . 'MainController/Student_Login/.$user_email.')

Please Help.

like image 578
Ajmal Razeel Avatar asked Jun 30 '16 11:06

Ajmal Razeel


People also ask

Can we pass data in redirect codeigniter?

Third, in the Controller that displays the form (to which you redirect back), check to see if there is any flashdata and retrieve it like so: $message = $this->session->flashdata('data_name'); You can then pass $message along to the View for being displayed above the form. And that's it.

Which function is used for page redirect in codeigniter?

Use redirect() helper function.


3 Answers

There is no need of adding base_url with redirect.

Just try

redirect('mainController/Student_Login/'.$user_email)

when user_email you will receive as argument in student_Login funciton

like image 109
Raj Jagani Avatar answered Sep 19 '22 10:09

Raj Jagani


You can pass it over session. If you want it available next request only, put it in session flash data.

First controller

public function method1()
{
    // if not loaded session library in APPPATH . 'config/autoload.php' load it in here

    $this->session->set_flashdata('user_email', $user_email);

    redirect('secondcontroller/method2', 'refresh');
}

Second controller

public function method2()
{
    // if not loaded session library in APPPATH . 'config/autoload.php' load it in here

    $user_data = $this->session->flashdata('user_email');

    // when flash data is set, after this request it will be unset from $_SESSION array
}
like image 21
Tpojka Avatar answered Sep 20 '22 10:09

Tpojka


Use it as with out base_url()

redirect('MainController/Student_Login/'.$user_email);

And in method you get it using

function Student_Login($user_email){
    echo $user_email;
    //...
}
like image 21
Saty Avatar answered Sep 19 '22 10:09

Saty