Outlaws35

Understanding the MVC Pattern

Posted by: jogisilalahi on: July 23, 2009

The MVC (Model View Controller) pattern is a commonly used design pattern in software development, where the code is separated into three major parts:
models, views, and controllers.
The exact purpose of each part depends on the implementation, as it may vary from one framework to another. Here, we are going to describe the way CakePHP implements the MVC pattern. So, this is not a general discussion on MVC pattern, rather we are only going to see Cake’s own MVC implementation. As we have already mentioned, CakePHP separates the code into three separate parts: models, views, and controllers.

Models
In CakePHP, a model represents a particular database table. Each database table should have a model representing it. So, in CakePHP, every database table has its own model. All PHP code related to accessing, adding, modifying or deleting records from the table are situated in the model. The model also contains code that deines its relationship with other models. Other than that, the model also deines the data validation rules when adding or updating data for that model. Model can be thought of as the data layer of the application. The model is also the place where the business logic related to the model should be deined. For example, if we have a model to represent cars, all actions related to it like buy car, sell car etc. should be deined in the model. Models should be the place where the core business logic of an application are deined.

Controllers
Controllers, in CakePHP, control the application low or logic of the application. Each web request is directed to a particular controller where the user input (POST or GET data) is accepted. The controller logic then decides what response is generated. The controller logic normally contains calls to models to access data, and also other functionalities like access control check etc. Lastly, the controller passes the response (output) to the view (discussed next). Controller can be thought as the control logic layer of the application. As mentioned above, the model should have all the business logic of an application. The controllers should just delegate the actions to the model, and be light. This design philosophy is sometimes referred to as the “fat models and thin controllers”.Chapter 1

Views
Views are the outputs or responses that are sent back to the user once a request is processed. They basically consists of markup (like HTML) code with embedded PHP code, but they can also be other forms of output like XML, PDF document etc. depending on the situation. Views can be thought as the presentation layer of the application.

taken from :
CakePHP Application Development

Leave a Reply

my twitter

  • Bersiap untuk kembali.||3 weeks ago
  • Senam kali ini, lari2 keliling kampus (baca:dikejar pak si)||3 weeks ago
  • Hujan terus. Flu menyerang. Hanya bisa istirahat di asrama.||4 weeks ago
  • tidak bisaa ikut rilis Ubuntu KK bersama MedanLinux dan OSUG Medan. Sedih!||1 month ago
  • Besok ujian terakhir. Tapi gak d kasih pulang sorenya.||1 month ago

kalender

July 2009
M T W T F S S
« Jun   Aug »
 12345
6789101112
13141516171819
20212223242526
2728293031  

blog stats

  • 5,127 hits

counter

page rank


PageRank

me and sponsors


Visit ITapanuli
Visit Politeknik Informatika Del on OSUM
Jogi Silalahi
Jogi Silalahi
Create Your Badge

Sun Microsystems

Digital Open

OpenSolaris


Linux


Fedora Project


Open Solaris Org


OpenSolaris User Group


OSUM Member


OSOL Indonesia


Sun Student Developer Indonesia


ITapanuli, Learning Community


Open Solaris User Group Medan

referal link





Masukkan Code ini K1-5D2B4B-3
untuk berbelanja di KutuKutuBuku.com






award dari mekkelbojak.blogdetik.com