The right way to redirect - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: The right way to redirect (/showthread.php?tid=29660) |
The right way to redirect - El Forum - 04-16-2010 [eluser]zoonix[/eluser] Hey all, I'm still having lots of fun learning about CI and I'm hoping there are a couple more kinds souls that might share some pointers with me. All I'm trying to figure out is how to handle things after calling a function. In my test code below I have tried two ways of loading the view once the function is done. In delete_file I tried $this->index which works except the list of files still shows the deleted file until you refresh. In the upload function I tried using redirect('dev/test', 'refresh') which works fine by bringing me back to the index and refreshes the file list nicely, but I lose the data in $data['message']. I'm sure that I'm making this much more difficult than need be. Any suggestions? What is the recommended way of doing this? Thanks!! Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); The right way to redirect - El Forum - 04-16-2010 [eluser]connors[/eluser] I'd use Code: redirect(site_url('dev/test'), 'refresh'); To get the message to another page, use flash data. Code: $this->session->set_flashdata('upload_message', 'Successfully uploaded '.$data['data']['upload_data']['orig_name']); Code: if(isset($this->session->flashdata('upload_message')) echo $this->session->flashdata('upload_message'); The right way to redirect - El Forum - 04-16-2010 [eluser]cahva[/eluser] [quote author="connors" date="1271464638"]I'd use Code: redirect(site_url('dev/test'), 'refresh'); [/quote] Sorry but you're wrong about this. redirect function already uses site_url function so you dont have to add it anymore. So just redirect('dev/test') will do fine. But with flashdata I agree 100% Thats the way to inform something's changed. Action -> create flashdata -> redirect -> show flashdata The right way to redirect - El Forum - 04-16-2010 [eluser]zoonix[/eluser] Thanks guys! This that's exactly what I was looking for. It always seems so obvious when you get the answer. The right way to redirect - El Forum - 04-16-2010 [eluser]connors[/eluser] [quote author="cahva" date="1271468049"] Sorry but you're wrong about this. redirect function already uses site_url function so you dont have to add it anymore. So just redirect('dev/test') will do fine. [/quote] Thanks for the correction The right way to redirect - El Forum - 04-19-2010 [eluser]zoonix[/eluser] Thanks again for the help. Here's what I came up based of the suggestions. Pretty basic, but maybe it'll help some other newb like me. Controller... Code: // Delete file View... Code: <p><?php The right way to redirect - El Forum - 04-19-2010 [eluser]n0xie[/eluser] You could also try my message library to take care of sending status messages to an user. |