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.
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.
Use redirect() helper function.
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
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
}
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;
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With