
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 exchange all information and directories in your system/ listing and exchange 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 duplicate 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 should transfer them to software/core/:
software/libraries/Log.php
-> software/core/Log.php
software/libraries/Enter.php
-> software/core/Enter.php
3- Replace your lessons 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- Change config/mimes.php
mimes.php
config file has been up to date in 3.x to comprise extra person mime-types. Please exchange mimes.php config file with new 3.x codeigniter mimes.php config file.
5- Replace your Session library utilization
The Session Library has been utterly re-written in CodeIgniter 3 and now comes with a brand new options.
- The desk session desk construction has modified a bit:
- session_id discipline is renamed to id
- user_agent discipline is dropped
- user_data discipline is renamed to knowledge and beneath MySQL is now of kind BLOB
- last_activity discipline is renamed to timestamp
- Earlier than Codeigniter 3.x unset_userdata perform 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 must go worth.
$this->session->unset_userdata(array('identify' => 'abc', 'e mail' => '[email protected]')); -> $this->session->unset_userdata(array('identify', 'e mail'));
6- Change your error templates
In CodeIgniter 3.x the error templates at the moment are thought-about as views and have been moved to the applying/views/errors/html listing. Moreover in Codeigniter 3.x, there may be help for CLI error templates in plain-text format that in contrast to HTML. You’ll be able to transfer your outdated 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 Lively Report to Question Builder inside your config/database.php.
you have to 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 symbolize with .+.
That is thought-about a bug because it additionally matches the / (ahead slash) character which is the URI phase delimiter.
In CodeIgniter 3 the :any wildcard will now symbolize [^/]+, 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 objects
Many strategies and features now return NULL as an alternative of FALSE when the required objects 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() perform to generate a SHA1 hash.
Safety helper do_hash()
In 3.x, Codeigniter now makes use of PHP native hash() perform as an alternative of do_hash() perform.
String helper trim_slashes()
In Codeigniter 3.x now makes use of trim() perform as an alternative of trim_slashes().
Kind helper form_prep()
In Codeigniter 3.x now makes use of html_escape() perform as an alternative of form_perp() perform.
Date helper standard_date()
Date Helper perform standard_date() is being deprecated in Codeigniter 3.x because of the availability of native PHP constants. Which when mixed with date() perform present the identical performance.
12- Improve your CodeIgniter 2 software now!
You’ll be able to e 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