Following are the step to improve your legacy CodeIgniter 2.x utility into CodeIgniter 3.x utility. CodeIgniter 3.x helps new variations of PHP and has extra safety and quicker execution.
1- Replace your CodeIgniter recordsdata
Go to system folder change all recordsdata and directories in your system/ listing and change your
If any modifications had been made to your
index.php they are going to have to be made contemporary on this new one.
when you have any customized developed recordsdata 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 positioned within the system/core/ listing. Subsequently, to ensure that your Log class overrides or extensions to work, it’s essential to transfer them to utility/core/:
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:
4- Change 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 below MySQL is now of sort BLOB
- last_activity subject is renamed to timestamp
- Earlier than Codeigniter 3.x unset_userdata operate used to simply 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', '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 of as views and have been moved to the appliance/views/errors/html listing. Moreover in Codeigniter 3.x, there may be help for CLI error templates in plain-text format that not like HTML. You may transfer your previous recordsdata from utility/errors to utility/views/errors/html however it’s a must to copy the brand new utility/views/errors/cli listing from the CodeIgniter 3.x and previous into utility/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 all the time supplied the :any wildcard in routing. In Codeigniter 2.x the :any wildcard is signify 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 signify [^/]+, 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 not added by default and has an optionally available second parameter [TRUE]
and is ready to FALSE by default.
$this->dbforge->drop_table(‘table_name’); -> $this->dbforge->drop_table(‘table_name’, TRUE);
10- Many capabilities now return NULL as a substitute of FALSE on lacking gadgets
Many strategies and capabilities now return NULL as a substitute of FALSE when the required gadgets don’t exist.
11- Take away beforehand deprecated capabilities
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 a substitute of do_hash() operate.
String helper trim_slashes()
In Codeigniter 3.x now makes use of trim() operate as a substitute of trim_slashes().
Kind helper form_prep()
In Codeigniter 3.x now makes use of html_escape() operate as a substitute 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 utility now!
You may e-mail to debate with CodeIgniter knowledgeable to replace your 2.x utility to a more recent 3.x and 4.x variations.
Associated: 8 Steps to CodeIgniter efficiency optimization