Posted by Oliver Grätz on 04/20/07 01:15
Harris Kosmidhs schrieb:
> I was googling for a tutorial on how I can make an MVC framework for a
> small application. Unfortunately all the results pointed out to well
> known MVC frameworks like CakePHP.
First of all: Why write a new framework instead of using one?
And then: The existing frameworks ARE the tutorials. The concepts behind
MVC are very general and so instead of having THE tutorial there are
many examples showing one or the other way of implementing MVC.
But OK, the minimalistic tutorial for MVC:
MVC means ModelViewController and this means that you should divide your
application into these three components:
1. The model
All your business logic (aphorism for "da whole buncha SQL") should be
seperated from the rest of your app. For example, create one class per
database table. Example For the table "adresses" use a class DbAdress
and put actions dealing with adresses into this class.
2. The view
This is the mantra of never putting code and layout too close together.
Use some kind of template system - even PHP itself can be used in such a
way - and you can put a checkmark behind the V.
3. The Controller
Basically there is no real definition for this. The controller is
somehow the glue that puts all other pieces of your app together. There
are standard concepts like the front conroller (everything in the app is
reachable via index.php) and action controllers (the "main" method for
any given page (action) is a method in a class (module/package/category).
Everything going beyond this basic ideas is just evangelism. Every
framework does ist a little bit different and some do it COMPLETELY
different but still call themselves MVC.
OLLi
--
"I love a good slaughter as much as the next bloke."
[Spike, Buffy 217]
[Back to original message]
|