In this article, we will discuss why Codeigniter is called a loosely based MVC framework? Let’s first discuss what is Codeigniter and why we use it? Codeigniter is PHP based framework used to develop applications. If you are familiar with PHP then learning Codeigniter would be easier. Codeigniter is an open-source framework. It has rich libraries support.
Features of Codeigniter: Some of the features of Codeigniter are listed below:
- It follows MVC architecture
- It is lightweight and clear documentation is available
- Form and data validation
- Sending Emails and more
- Security
- Query builder
- Pagination
- Unit Testing Class
- Localization
MVC architecture: Codeigniter follows MVC architecture. MVC architecture is an approach in which we focus on 3 components:
- Model
- View
- Controller
Model
The model mainly deals with data. If we want to interact with the database then the model is responsible for it. You can think of it as your database part. The most important concept is that controller doesn’t talk with the database directly. Model responds to the controller request. The controller request the model when it needs some data then the model communicates with the database and fetches the necessary database and gives the required data to the controller.
View
The view is something that is being represented to the user. It is a UI interface for the user. For example when we visit GFG official website then UI represents the view. View communicates with the controller. We fetch the data from the database and then show it to the user using view. View communicates with the controller and then the controller talks with the model to fetch the data from the database.
Controller
It acts as an intermediate between view and model to process the request. It shows a suitable view(UI) to the user based on the incoming requests. When some data needs to be shown to the user then the view communicates with the controller and then the controller communicates with the model for the data. Because view can’t directly communicate with the model.
Advantage of MVC architecture: Following is the advantage of MVC architecture:
- Easy to maintain
- The user interface is separate from business logic
- Individual components can be deployed and maintained
- Components are reusable
Why Codeigniter is called a loosely based MVC framework?
As of now, we learned that Codeigniter is based on MVC architecture. Now we will discuss why it is a loosely based MVC framework? Codeigniter is known as a loosely based framework because, as we know it is an MVC-based PHP framework, the controller is the only necessary element. Model and views are not mandatory. There is no need to follow and strict pattern. In the case of Codeigniter controller play a vital role but the model and view are optional. It means we can create a website without a model also.
In short, because of the following points, Codeigniter is loosely based MVC framework
- We can develop an application without the model and view also
- The only controller is a necessary component.