• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
controller redirect to method fails

#6
Following up: Full code examples below of what worked and didn't...

Thanks for all the suggestions.  Most failures end with a CI4 code exception: SYSTEMPATH/HTTP\Exceptions\HTTPException.php at line 106

The root problem for me is simply vague documentation about reverse routing.  I've just no desire to poor through the CI4 system code.
I should mention I'm writing modules in different directories and namespaces with a "global" config, so I needed a general solution to redirect routing, etc...

PHP Code:
<?php namespace App\Controllers;
use 
CodeIgniter\Controller;
class 
Home extends Controller
{
    
//--------------------------------------------------------------------
    // Just jump to a different controller...  
        // Remember to add the route: $routes->get('/(:any)', 'Home::$1');
    
        
public function index()
    {
        
// in CI3:  redirect('dummy');  // traditional.

 
               // in CI4:
        
return redirect()->tobase_url('dummy') ); // this works (preferred solution I think)

        //return redirect()->to('ci4/dummy'));         // this works (/ci4 is my new "public" dir)
        //$this->response->redirect('dummy');       // this also works
                //$this->response->redirect(base_url('dummy')); // this version also works

        // return redirect("dummy");              // fails with CI code exception
        // return redirect(base_url('dummy'));    // fails with CI code exception
        // return redirect('App/Controller/Home::dummy');    // fails with CI code exception
        
    
}

    
//--------------------------------------------------------------------
    
public function dummy()
    {
        echo 
"Dummy route.";
    }

Reply


Messages In This Thread
controller redirect to method fails - by devops - 03-12-2019, 09:25 AM
RE: controller redirect to method fails - by devops - 03-13-2019, 02:00 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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