I'm new to Codeigniter, and I want redirect to a controller after the validation is fall:
if(!validate)
{
redirect('/poll/list');
}
but I need to pass a variable like $error
to show the some error indication, but I don't know how to pass the parameter to redirect
method in the URL helper
, and idea?
You can then pass $message along to the View for being displayed above the form. And that's it. User submits the form, the form gets processed by another Controller method, the latter stores the message in the session flashdata and redirects the user to the original Controller method that loads the form.
Yes. If not passing the object, then passing the id so that the other function can retrieve it from the database.
Use session flashdata - this is exactly what it is designed for:
if(!validate)
{
$this->session->set_flashdata('error', 'your_error');
redirect('/poll/list');
}
Then inside your poll/list function:
$error_msg = $this->session->flashdata('error');
base url = 'http://localhost/site/'
URL http://localhost/site/controller/method
$this->uri->segment(1) = 'controller'
$this->uri->segment(2) = 'method'
Now check the below case also
base url = 'http://testsite/test/site/'
URL http://testsite/test/site/controller/method
$this->uri->segment(1) = 'controller'
$this->uri->segment(2) = 'method'
Pass your message
http://testsite/test/site/controller/method/meesage
and use
$this->uri->segment(3)
You can use session also instead passing message through URL
..
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