CodeIgniter is a very famous framework among PHP developers. It’s very fast in comparison to another PHP framework also with less file size.
So till now CodeIgniter 3 was used to develop the projects and now CodeIgniter 4 has been officially released for use in the projects.
In this blog, we will understand the main differences between CodeIgniter 3( old framework ) and CodeIgniter 4 ( latest release).
Codeigniter 4 can be download by two methods. first is to use the composer and the second is using ready to run zip file from the CodeIgniter official website.
Codeigniter 4 is build for PHP 7.2+ versions. so you can say its build for the mainly latest version of PHP. and everything in the framework is namespaced, except for the helpers.
It is not compatible with the old version of CodeIgniter. so if you want to use CodeIgniter 4 then definitely you have to give some more effort to update. because in the last versions it was very easy to update but in this update, they have added a lot of new features that are the reason it’s not compatible with the oldest version of CodeIgniter.
Application Structure –
- The application folder is renamed as app and the framework still has system folders, with the same interpretation as before
- The framework now provides for a public folder, intended as the document root for your app
- There is also a writable folder, to hold cache data, logs, and session data
- The app folder looks very similar to the application for CI3, with some name changes, and some subfolders moved to the writable folder
- Now there is not nested application/core folder because now in CI4 there is a different mechanism to extend the framework component.
- In Codeigniter 4, You have to extend \Codeigniter\Controller instead of CI_Controller
- In this version, they do not use any constructor to use CI magic. now it is the part of the base controller which you will make.
- The new thing is that CI4 provides Request and Response object to work. It’s more powerful than the CI3 way.
- If you want to use your controller to use as a Base Controller then make your controller anywhere you like and extend Controller and then use it anywhere you want.
- Same as controller now the model will not extent CI model you have to extend \Codeigniter \Model.
- In the CI4 model, there are more functionalities than CI3 including automatic database connection, basic CRUD, in -model validation and automatic pagination.
- instead of writing in CI3 $this->load->model(x) now you have to write $this->x = new X():
- CI4 has Entity class also to use richer data mapping to database tables;
- Instead of writing in CI3 $this->load->view(x) you can use echo view(x);
- CI4 supports view cells to build your responce in pices.
- Instead of writing $this->load->library(x) now you can use $this->x = new X();
These were some syntax and updations which are changed in CI4.
Thanks for reading this blog. if you have any doubts then do not hesitate to ask in the comment section also if you have any suggestions then I will like to here on my mail email@example.com.