Welcome Guest, Not a member yet? Register   Sign In
Routes for large CI3 to CI4 upgrade
#5

Thank you!  

My colleague came up with a solution that helps with routing pages between CI3 and CI4 while we migrate pages.  It doesn't solve the session issue either, but we don't have a need for that at this time.

For the solution she implemented, we have CI4 running in a subdirectory within CI3.  

CI3 has a controller called CI4redirector, and CI4 has a controller called CI3redirector.  When we finish converting a page to CI4, we can add a route to the CI3 application/config/routes.php.  For example, if we finish the news page our route would look like $route['news']='CI4redirector/ci4/news';  That would redirect the user to CI4.  However, we want links on that CI4 page to direct to CI3 or CI4, depending on if we have converted that page or not.  To achieve this, we use the CI3redirector within CI4 which routes back to CI3.

Here is the code in the CI4redirector controller (located in \application\controllers\CI4redirector.php)

Code:
class CI4redirector extends CI_Controller {

    public function __construct(){
            parent::__construct();
    }
   
    // redirect to CI4 site
    public function ci4($base, $seg=NULL) {
       
        $newPath = base_url() . "CI4/$base";
        if ($seg) $newPath . "/$seg";
        //echo "new path is: $newPath";
       
        redirect($newPath, 'location', 301);
    }
   
}

Here is the code in the CI3redirector controller (located in \CI4\app\Controllers\CI3redirector.php)

Code:
namespace App\Controllers;

use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;

class CI3redirector extends BaseController {
   
    protected $baseURL_ci3;
   
    public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request, $response, $logger);
           
        $config = config('App');
        $this->baseURL_ci3 = $config->baseURL_ci3;           
    }
   
    // redirect to CI3 site
    public function ci3($base, $seg=NULL) {
       
        $newPath = $this->baseURL_ci3 . "$base";
        if ($seg) $newPath . "/$seg";
        //echo "new path is: $newPath";
       
        // use php not CI4 redirect for "external" location
        header("location: $newPath");
    }
   
}
Reply


Messages In This Thread
RE: Routes for large CI3 to CI4 upgrade - by xanabobana - 03-13-2024, 11:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB