
Upgrading PHP CodeIgniter 2.x model undertaking to three.x
Following are the step to improve your legacy CodeIgniter 2.x software into CodeIgniter 3.x software. CodeIgniter 3.x helps new variations of PHP and has extra safety and quicker execution.
1- Replace your CodeIgniter information
Go to system folder change all information and directories in your system/ listing and change your index.php
file.
If any modifications have been made to your index.php
they’ll have to be made contemporary on this new one.
when you’ve got any customized developed information in system folder please make a replica of them first.
2- Transfer your Log class overrides or extensions
The Log Class is taken into account as a core class and is now situated within the system/core/ listing. Subsequently, to ensure that your Log class overrides or extensions to work, you’ll want to transfer them to software/core/:
software/libraries/Log.php
-> software/core/Log.php
software/libraries/Enter.php
-> software/core/Enter.php
3- Replace your courses file names
In Codeigniter 3.x all class filenames (controllers, mannequin, drivers, libraries) should begin with a capital letter. For examples:
Library
software/libraries/mylibrary.php
-> software/libraries/Mylibrary.php
Controllers
software/controllers/welcome.php
-> software/controllers/Welcome.php
Fashions
software/fashions/welcome_model.php
-> software/fashions/Welcome_model.php
4- Exchange config/mimes.php
mimes.php
config file has been up to date in 3.x to comprise extra person mime-types. Please change mimes.php config file with new 3.x codeigniter mimes.php config file.
5- Replace your Session library utilization
The Session Library has been fully re-written in CodeIgniter 3 and now comes with a brand new options.
- The desk session desk construction has modified a bit:
- session_id subject is renamed to id
- user_agent subject is dropped
- user_data subject is renamed to knowledge and beneath MySQL is now of sort BLOB
- last_activity subject is renamed to timestamp
- Earlier than Codeigniter 3.x unset_userdata operate used to just accept an associative array of ‘key’ => ‘worth’ pairs for unsetting a number of keys.
- Now Codeigniter 3.x solely key as the weather of array no have to move worth.
$this->session->unset_userdata(array('identify' => 'abc', 'electronic mail' => '[email protected]')); -> $this->session->unset_userdata(array('identify', 'electronic mail'));
6- Exchange your error templates
In CodeIgniter 3.x the error templates at the moment are thought of as views and have been moved to the appliance/views/errors/html listing. Moreover in Codeigniter 3.x, there’s assist for CLI error templates in plain-text format that not like HTML. You may transfer your previous information from software/errors to software/views/errors/html however it’s important to copy the brand new software/views/errors/cli listing from the CodeIgniter 3.x and previous into software/views/errors/cli listing.
7- Replace Config/database.php file
In Codeigniter 3.x renaming of Energetic Report to Question Builder inside your config/database.php.
you will have to rename the $active_record variable to $query_builder with true worth.
// $active_record = TRUE;
$query_builder = TRUE;
8- Replace your config/routes.php any wildcard
CodeIgniter has at all times offered the :any wildcard in routing. In Codeigniter 2.x the :any wildcard is characterize with .+.
That is thought of a bug because it additionally matches the / (ahead slash) character which is the URI phase delimiter.
In CodeIgniter 3 the :any wildcard will now characterize [^/]+, so that it’s going to not match a ahead slash.
9- Replace utilization of Database Forge’s drop_table() technique
In Codeigniter 3.x the IF EXISTS situation is now not added by default and has an elective second parameter [TRUE]
and is about to FALSE by default.
$this->dbforge->drop_table(‘table_name’); -> $this->dbforge->drop_table(‘table_name’, TRUE);
10- Many features now return NULL as an alternative of FALSE on lacking gadgets
Many strategies and features now return NULL as an alternative of FALSE when the required gadgets don’t exist.
uri->phase(), session->flashdata();
11- Take away beforehand deprecated features
The SHA1 library
In Codeigniter 3.x beforehand deprecated SHA1 library has been eliminated now your code to make use of PHP’s native sha1() operate to generate a SHA1 hash.
Safety helper do_hash()
In 3.x, Codeigniter now makes use of PHP native hash() operate as an alternative of do_hash() operate.
String helper trim_slashes()
In Codeigniter 3.x now makes use of trim() operate as an alternative of trim_slashes().
Type helper form_prep()
In Codeigniter 3.x now makes use of html_escape() operate as an alternative of form_perp() operate.
Date helper standard_date()
Date Helper operate standard_date() is being deprecated in Codeigniter 3.x as a result of availability of native PHP constants. Which when mixed with date() operate present the identical performance.
12- Improve your CodeIgniter 2 software now!
You may electronic mail to debate with CodeIgniter skilled to replace your 2.x software to a more moderen 3.x and 4.x variations.
Associated: 8 Steps to CodeIgniter efficiency optimization