Open In App

Explain basic structure of a MVC model

Improve
Improve
Like Article
Like
Save
Share
Report

Models, Views, and Controllers (MVC) patterns are used by CodeIgniter to organized the files. This helps us to maintain the data, the presentation, and flow through the application. To make things more clear we can understand with their basic definition:

  • Models manage the data of the application and help to enforce any special business rules that the application might need.
  • Views are simple files, with little to no logic, that displays the information to the user that is received through controllers.
  • Controllers act as bridges, marshaling data back and forth between the view (or the user that’s seeing it) and the data storage.

In the most basic way of understanding, controllers and models are simply classes that have a specific job. They are not the only class types that you can use they also make up the core of how this framework is designed to be used. They even have designated directories in the /app directory for their storage of files like controllers, models, views, helpers, config, and many more, though you’re free to store them wherever you desire, as long as they are properly named.

Introduction To Models:< A model’s job is to maintain a single type of data for the application. This might be users, blog posts, transactions, etc. In this case, the model’s job has two parts:

  1. Enforce business rules on the data as it is pulled from, or put into, the database.
  2. Handle the actual saving and retrieval of the data from the database.

For many developers, the confusion comes in determining what business rules are enforced. It simply means that any restrictions or requirements on the data are handled by the model. This might include normalizing raw data before it’s saved to meet standards and requirements, or formatting a row/column in a certain way before handing it to the controller. By keeping these business requirements in check to the model, you won’t repeat code throughout several controllers or accidentally miss updating an area. Models have typically stored in the “/app/Models” location in their file structure.

Directory of Models in “/app” folder.


Last Updated : 14 Feb, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads