• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SOLVED - Redirect problem

#1
[eluser]RJ[/eluser]
Hello,

Using the code below I've narrowed down an issue i am having to a redirect problem
Code:
$redirect = ''.$this->lang->lang.'/shop/device/'.$this->dealer->dealer.'/plan';
            log_message('debug',  'REDIRECT :'.$redirect.'');
            redirect($redirect);

Looks all goofy because I've been trying to break it down to the error. It appears the /plan part of the URI is not being passed! I see it in the log

Quote:REDIRECT :en/shop/device/999/plan

Here is the method handling the request:
Code:
function device($dealer = '999', $page = 'personal_information')
    {
        $this->benchmark->mark('code_start');
        // start benchmarking
        
        # Load stuff
        $this->load->helper(array('form'));                    // load helpers
        $this->load->library('form_validation');            // load libraries    
        $this->form_validation->set_error_delimiters('<pre class="alert">', '</pre>');
        $this->load->model('dealer_model','dealer');        // load dealer
        $this->load->model('suw_model', 'suw');                // load suw
        $this->load->model('common_model', 'common');        // load common
        $this->lang->load('suw_main');                        // load language
        
        # Set dealer params
        $this->dealer->set_dealer($dealer);        // passes db info to dealer model for processing
        $this->load->model('Trimtrac_model', 'trimtrac');    

        //echo $this->lang->lang;
        switch($page)
        {
            case "personal_information":
                $this->page_one();
                break;
            
            case "plan":
                log_message('debug',  'MADE IT TO THE CASE');
                $this->page_two();
                break;
            
            default:
                $this->page_one();
                break;
        }
                
        // end benchmarking
        $this->benchmark->mark('code_end');
    }

Log shows I get all the way to the redirect then am sent to a 404 error rather than the specified URL. In the browser bar the /plan part is missing.

Any thoughts?

#2
[eluser]TheFuzzy0ne[/eluser]
That's a strange one. Even without the last parameter, your controller method should set $page to the default "personal_information", but it certainly shouldn't show a 404 error. I can only conclude that the redirect URL is somehow wrong, or that you have a route interfering somewhere. What changes do you have to make to the URL in your browser's address bar to make it work?

#3
[eluser]RJ[/eluser]
The solution may be one of many changes I made; most notably using "refresh" in the redirect.
Code:
redirect($redirect, 'refresh');

Also moving the form validation library load into the page switch rather than loading globally for the device method likely contributed.
Code:
case "personal_information":

                // Load stuff
                $this->load->library('form_validation');            // load libraries
                $this->form_validation->set_error_delimiters('<pre class="alert">', '</pre>');
                
                $this->page_one();
                break;

Finally I was able to trouble shoot by adding a $debug to the methods params like:
Code:
function device($dealer = '999', $page = 'personal_information', $debug = FALSE)

Calling upon a class var, setting TRUE if debug is TRUE:
Code:
if($debug == true) {$this->error_debug = true;}

Note I can only properly access the debug by completely filling out the URL like:
Code:
s/en/shop/device/personal_information/999/debug

Finally debug usage example:
Code:
if($this->error_debug)
                {
                   log_message('debug',  'MADE IT TO PLAN INFORMATION THE CASE');
                }

Hope this helps someone.

Best


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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