How to pass parameter to redirect method in URL helper in Codeigniter?

I'm new to Codeigniter and I want to redirect the controller after the validation has fallen:

if(!validate) { redirect('/poll/list'); } 

but I need to pass a variable like $error to show some indication of the error, but I don’t know how to pass the parameter to the redirect method in the URL helper , but idea?

+6
source share
2 answers

Use session flashdata - this is exactly what it is intended for:

 if(!validate) { $this->session->set_flashdata('error', 'your_error'); redirect('/poll/list'); } 

Then inside your polling / list function:

 $error_msg = $this->session->flashdata('error'); 
+12
source
 base url = 'http://localhost/site/' 

URL http://localhost/site/controller/method

 $this->uri->segment(1) = 'controller' $this->uri->segment(2) = 'method' 

Now check also the example below

 base url = 'http://testsite/test/site/' 

URL http://testsite/test/site/controller/method

 $this->uri->segment(1) = 'controller' $this->uri->segment(2) = 'method' 

Send your message

http://testsite/test/site/controller/method/meesage

and use $this->uri->segment(3)

You can use a session and instead pass the message through the URL ..

+1
source

Source: https://habr.com/ru/post/927632/


All Articles