• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redirect with input

#1
I think we need something similar like in Laravel: 
https://laravel.com/docs/5.3/responses#r...ssion-data
https://laravel.com/api/5.2/Illuminate/H...ponse.html

Why we need this? To show the form in one action method and in the other one handle the data processing...

For CodeIgniter 3 I use a similar but very simple solution to achieve the same results, see below...

I put the following code to the MY_Controller constructor:
PHP Code:
$_previous_data $this->session->flashdata('_previous_data');
if(
$_previous_data)
{
    
$_POST    $_previous_data['post'];
    
$_GET    $_previous_data['get'];


...and I created the following helper method for the redirect:
PHP Code:
if( ! function_exists('redirect_with_input'))
{
    function 
redirect_with_input($uri ''$method 'auto'$code NULL)
    {
        
$CI =& get_instance();

        
$data = array(
            
'post'    => $CI->input->post(),
            
'get'    => $CI->input->get()
        );

        
$CI->load->driver('session');
        
$CI->session->set_flashdata('_previous_data'$data);

        
redirect($uri$method$code);
    }


I am not saying we should use something similar, it's just here to show an implementation... Laravel's approach is much cleaner & have more options...
Reply

#2
Yes, something similar to this is on my radar, but I keep forgetting to work on it among all of the other parts. Thanks for the nudge and for sharing your code.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#3
(01-03-2017, 04:23 PM)kilishan Wrote: Yes, something similar to this is on my radar, but I keep forgetting to work on it among all of the other parts.  Thanks for the nudge and for sharing your code.

Okay, cool thx. Smile
Reply

#4
And it's in there.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#5
Great work! I was looking for such a function a few month back for a project. Good to see its getting integrated Smile
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.