CodeIgniter 2: Models, Controllers and Views

CodeIgniter approaches web development with MVC in mind. MVC is a way of presenting data that keeps programme logic and presentation separate from each other. This means that there is little PHP scripting in your presentation pages, keeping them clean and focused on looks.

MVC stands for Model, View, Controller with each being used for a specific function.

Models are typically where your programme will interact with the database e.g. inserting, updating and retreiving data.

Views are where your HTML will go, this is what will make the logic you create look good. Views don’t have to be conventional web pages. In the examples I will be showing I will be loading just a part of the page the header. By doing this it keeps individual page content separate as the header remains the same across all pages.

Controllers act as the middle man. They are what connect the users requests to the relevant view and retrieve any other resources that are required. This will also be where you put all your programme logic such as iterating over records from database and validating user input from forms etc.


This may have been quite a short post, however, I feel that CodeIgniters MVC approach needed explaining and a quick overview of what each patrt is and what code goes where was necessary.

Head over to the next post to check out how to create our first controller and view. Here

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s