Understanding MVC

Understanding MVC, or Model-View-Controller, is to using different programming frameworks, such as CakePHP, that untilize the programming architecture. MVC is fairly simple if explained correctly.

Model-View-Controller is a pattern, or architecture, used in software engineering. It allows the developer to create robust applications that are easy to modify. It is used to completely separate different aspects of creating an application. This can make applications that are dynamic and powerful.

Model

The model is the first part of MVC. It contains all of the data. In your model, you should organize the data in some way. Think of a model that is representing a user. The model will contain all of the data of the user, such as the user’s name and password, and all of the relationships of the user, such as the user’s parent group. The Model doesn’t do any of the thinking, it just holds the data. You can look at the database as the model for your application, although you might have some code to go along with it.

View

The view is probably the easiest to understand. The view is what the user sees when they access your application. It doesn’t do any thinking or storing, it just outputs what the user sees.

Controller

The controller is where all of the thinking happens. Your application will need to make calculations and modify data – this will happen here. In most cases, the controller is the linking point between the view and the model. It will take data from the model and then pass it on to the view to display in some way. When something changes, the controller tells the model to update. For example, if you have an text input box on your view, and a user inputs some text, the controller will tell the model to update according to the input.

The MVC architecture is used by CakePHP. I will be going into more detail about MVC and how it relates to CakePHP in later posts.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>