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

Hello, 
The nonprofit organization I work for uses Codeigniter for a very large codebase (around 100 controllers and 750 views).  We are planning to upgrade from CI3 to CI4 this year.  Since our codebase is so large, we are looking at some sort of routing system that would allow us to  have some pages in CI3 and some in CI4 as things are upgraded.
So maybe we would have specific routes for pages that have been upgraded to CI4, but then a rule that routes everything else to CI3.
I'm wondering if anyone else has dealt with this type of migration before, and could share examples of how you dealt with this?
Thank you!
Reply
#2

See https://forum.codeigniter.com/showthread.php?tid=89311
Reply
#3

This isn't what I was asking. We actually have CI3 and CI4 running together with CI4 in a subdirectory.

What I'm looking to do is have it so when I convert a page to CI4, we route to the CI4 subdirectory. Otherwise, we route to CI3. So links in the CI4 page would still go to CI3 unless there is a page in the CI4 subdirectory. Since we have so many pages and the conversion is estimated to take a year we are hoping to roll out as we go and not wait to convert everything to roll it out.

Any ideas on how to route like that?

Thank you!
Reply
#4

See https://forum.codeigniter.com/showthread...pid=414435
Reply
#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




Theme © iAndrew 2016 - Forum software by © MyBB