CodeIgniter, the featherweight of PHP frameworks
CodeIgniter is preferred as a web application framework by developers who prioritize speed over an advanced range of features. The central objective that has guided the design of this open source PHP development environment is, according to the project website, to obtain maximum performance and flexibility with a minimum of code.
What is CodeIgniter?
It is a web development environment written in PHP that boasts of accelerating and optimizing the development of web applications thanks to a compact software design. The North American software company EllisLab was responsible for its creation and publication of its first version in February 2006. A year after announcing, on July 9, 2013, that the company no longer had the necessary resources to continue developing the software, the project benefited from its acquisition by the British Columbia Institute of Technology (BCIT).
The CodeIgniter source code is distributed under an MIT license and can be downloaded from the GitHub platform . The latest stable version of the development environment, CodeIgniter 3.1.2, is offered for free download on the official project page .
The structure of CodeIgniter
The performance-oriented design of this web development framework is revealed in its lean architecture, as it is based on the Model-View-Controller (MVC) pattern. The fundamental principle underlying the MVC development architecture is the strict separation between code and presentation, thanks to custom software development services and the externalization of PHP code. This separation is carried out in these three groups: the model, the view and the controller, which we explain below:
- The model represents the data structure of a web application developed with CodeIgniter. To do this, the so-called classes (“model classes”) are defined in the source code, which contain special functions with which the information in the database can be received, inserted or updated.
- The view is what is presented to the end user. Generally, it is an HTML document in which content has been dynamically inserted with PHP, becoming a kind of template. CodeIgniter also allows you to define fragments of a web page as the header and footer or RSS pages as a view. Normally web applications use several views, which take their content from the same model, so that it is possible to present various program characteristics in different views.
- The controller mediates between the model, the view, and any other resources needed to process an HTTP request or dynamically generate a web page. This component receives incoming requests, validates the input, selects the desired view, and delivers the content that the model has loaded from a database.
The MVC framework allows for flexible software design, as individual programming modules can be replaced, edited and reused very easily. Changes made to one component usually have no effect on the source code of other components, as long as these changes do not take place at the points of contact between them.
The aforementioned division between program logic and presentation results in clear and well-structured code. This is what makes web applications designed according to an MVC pattern considered easy to maintain, since, in the event of an error or failure, the source is usually found in only one of the components. This separation also allows logic and design to be developed independently. If backend and frontend developers work in parallel, applications can be finished much more quickly.
Even though CodeIgniter uses the MVC pattern, users are not required to do so entirely. If the controller and the view are mandatory components, the same is not true for the model, whose use as a link to the database is merely optional. An application made with CodeIgniter can also be made with a hierarchical MVC (HMVC) architecture, which would extend the classic MVC pattern with hierarchical logic.
Advantages of using CodeIgniter
With more than 14,000 stars on GitHub, CodeIgniter is a development project with a remarkable reputation, ranked third among the most popular PHP frameworks. However, like any software, CodeIgniter has both advantages and disadvantages that must be considered before deciding on it.
These are the advantages of CodeIgniter:
- Easy setup : It's easy to get started with CodeIgniter. Your users do not need to take excessive time configuring the framework, but almost immediately after installing it, they can begin developing the application. The settings essentially boil down to the config.php document in the application/config/ directory . Here, framework users define a standard path for browser access, a key for encryption, a name for the session cookie, and settings for Cross-Site-Scripting (XSS). It would also be appropriate to create an .htaccess file to be able to remove the index.php from the application address with RewriteRule , as well as it is necessary to configure the connection with the database that is introduced in the database.php file .
- Small Footprint: CodeIgniter leaves a very small footprint on the system, as the framework download package only reaches 11 MB, with 9 MB occupied only by the detailed software documentation. The reason for the small code size is that the basic framework system only includes a couple of libraries. All necessary additional resources can be installed afterwards .
- Exceptional performance: This simple basic structure leads CodeIgniter to surpass other PHP frameworks in speed, something already praised at the time by PHP inventor Rasmus Lerdorf, among others. In 2008, Lerdorf surprised everyone by declaring, at the Free and Open Source conference (FrOSCon), that he liked CodeIgniter for being “faster, lighter and less similar to a framework” (“because it is faster, lighter and the "least like a framework". Instead of implementing access to dynamic pages through Query Strings as other PHP frameworks do, CodeIgniter leans towards a segment-based principle:
- Clean URLs: CodeIgniter automatically generates human- and machine-readable addresses. Instead of implementing access to dynamic pages using Query Strings as other PHP frameworks do, CodeIgniter leans towards a segment-based principle:
- Free programming style : the PHP framework is based on a free interpretation of the MVC architecture, which means that developers are free regarding the programming style they want to use.
- Extensive and detailed documentation : CodeIgniter provides its users with complete documentation in English, including a manual for beginners, available as an online guide and a downloadable version on the project website. Its source code is also clear and well commented.
- Support community : any developer who uses CodeIgniter to program applications has the support of other users, as the project is accompanied by a very active community that includes a public forum . Currently, more than 8,143 members participate in some 65,000 threads in which they exchange comments and opinions on the use and further development of the framework.
Disadvantages of Codelgniter
Due to the acquisition of BCIT, the development of the framework was temporarily stalled and, thus, the developers' attempts to implement technological advances in Codelgniter have been in vain.
- ORM only through third parties : Object relational mapping (ORM) refers to a software development services that allows applications to store objects written in an object-oriented programming language such as PHP in a database. relational data. Codelgniter does not support the ORM natively. However, this technology can be integrated.
- Does not have a templating engine – Codelgniter prides itself on working correctly without a templating engine. In return, this framework offers a simple template parser. This can be seen as an advantage, since, generally, the use of a templating engine is associated with a performance overhead (over and above the execution time). Additionally, the template language would also have to be learned. On the other hand, a templating engine allows data generation to be separated from the code for presentation, thus generating clearly structured source code. Using a templating engine with a lighter syntax can significantly reduce the overall code size of your application.
- There is no such thing as namespaces – With namespaces, PHP provides the ability to separate the code of different application groups. PHP developers make use of this feature to avoid conflicts that occur during the naming of classes and functions. For example, name collisions with internal PHP classes with functions, constants or built-in elements are very common. by third parties. So far, Codelgniter does not use this PHP function.
- It does not have the PHP class autoloading option : with __autoload() and spl_autoload_register(), since its fifth version, PHP has two functions that allow class definitions to be loaded automatically when necessary. This feature is not available in Codelgniter.
- Fewer built-in libraries than other PHP frameworks – Thanks to the software's lightweight design, Codelgniter's initial setup provides significantly fewer libraries than other PHP frameworks. First of all, these include the most important tasks of web development, such as accessing the database, sending email, validating form data, maintaining work sessions or working with XML – RPC. For those tasks that go beyond the basic functions, it will be necessary to integrate other libraries or external resources. Now, this can be advantageous for those developers who are looking for a framework whose functions are reduced to a minimum.
In conclusion: what projects is Codelgniter aimed at?
With its compact design and beginner-friendly syntax, Codelgniter is suitable for those aspiring to become programmers . Now, those who have already taken their first steps in dynamic web development based on PHP will also quickly become familiar with this lightweight framework. Even experienced custom software development companies will find great flexibility, guaranteed mainly thanks to the practical reduced functionality of this PHP framework. However, anyone who wants to work with Codelgniter will have to get used to the MVC pattern, as well as do without a template engine and a native ORM. Despite its small code size, Codelgniter is an ideal solution for small and large web projects alike.