Upgrade from CI3 to CI4 - By Running them together |
02-04-2024, 07:25 AM
(This post was last modified: 02-09-2024, 09:13 PM by mkganesh. Edit Reason: Additional info about vendor folder )
Below is the approach I took to start upgrading from CI3 to CI4.
Step 1: First make these below changes to your current(CI3) project. Create a folder public and move index.php into it. Open the public/index.php file and change $system_path = 'system'; to $system_path = 'system_ci3'; Rename your system folder to system_ci3 Step 2: Rename Constants This step is required as these CONSTANTS are used in both CI3 and CI4 and need to point to different locations. Change the below lines in the public/index.php file define('BASEPATH', $system_path); to define('BASEPATH_CI3', $system_path); define('FCPATH', dirname(__FILE__).DIRECTORY_SEPARATOR); to define('FCPATH_CI3', dirname(__FILE__).DIRECTORY_SEPARATOR); define('SYSDIR', basename(BASEPATH)); to define('SYSDIR_CI3', basename(BASEPATH_CI3)); define('APPPATH', $application_folder.DIRECTORY_SEPARATOR); to define('APPPATH_CI3', $application_folder.DIRECTORY_SEPARATOR); define('VIEWPATH', $view_folder.DIRECTORY_SEPARATOR); to define('VIEWPATH_CI3', $view_folder.DIRECTORY_SEPARATOR); Search for these 5 constants through out your project and replace them with new value. Once the values are replaced, test your project at this point. If all the values are replaced correctly there should be no errors. Step 3: Rename Functions in Common.php This step is required as these functions are named same in CI4. Rename the below function name in system_ci3/core/Common.php • log_message • function_usable • is_cli • is_really_writable • remove_invisible_characters find and replace for above functions through out system_ci3 and application folder. Step 4: Rename Functions in system_ci3/helpers This step is required as some of these functions are named same in CI4. Not all functions are available in CI4. This step is done for maintaining consistency and easier debugging if there are errors at later stages. Rename all the functions inside all the files in this folder. For Step 3 and Step 4, I just added _ci3 at end of each function. Eg: log_message was renamed to log_message_ci3 form_open was renamed to form_open_ci3 Please make sure you are replacing the correct functions as there can be same name functions inside a class, which need not be replaced. Eg: set_value in form_helper.php needs to be replaced. There is set_value function inside system_ci3/libraries/Form_validation.php, this need not be replaced. Test your project at this point, there should be no errors if everything was replaced correctly. Step 5: Download CI4 and place code in your project. Now download the latest CI4 code and copy the app, system, writable folders to your project’s base folder. Once copied you should have the following folder structure. • app - CI4 • application - CI3 • system - CI4 • system_ci3 - CI3 • public • writable If you are using modules from vendor folder, that can be moved to the base directory along side the above directories and path of it can be changed in application/config.php $config['composer_autoload'] = '/path/to/vendor/autoload.php'; Step 6: Running CI4 from CI3 In system_ci3/core/Controller.php file copy the below code. This is the code from codeigniter 4 public/index.php file. This loads CI4 application. PHP Code: public function load_from_ci4() { Now you should be able to start writing code in CI4. If you want to load the welcome controller, index function from CI4, just comment out all the existing code in index function and call load_from_ci4(). PHP Code: public function index() In the App/Config/Routes.php If you have PHP Code: $routes->get('welcome/index', 'Home::index'); |
Messages In This Thread |
Upgrade from CI3 to CI4 - By Running them together - by mkganesh - 02-04-2024, 07:25 AM
RE: Upgrade from CI3 to CI4 - By Running them together - by kenjis - 02-05-2024, 05:29 PM
RE: Upgrade from CI3 to CI4 - By Running them together - by kenjis - 02-05-2024, 05:33 PM
RE: Upgrade from CI3 to CI4 - By Running them together - by mkganesh - 02-25-2024, 05:38 AM
RE: Upgrade from CI3 to CI4 - By Running them together - by win123139 - 04-14-2024, 08:29 PM
RE: Upgrade from CI3 to CI4 - By Running them together - by mkganesh - 04-14-2024, 11:54 PM
RE: Upgrade from CI3 to CI4 - By Running them together - by win123139 - 04-15-2024, 01:26 AM
RE: Upgrade from CI3 to CI4 - By Running them together - by mkganesh - 04-15-2024, 03:29 AM
|