Alex Rivera | Logout

How to implement MVC from scratch in PHP?

Asked 2010-02-25T09:57:54.810
19

I would like to implement MVC from scratch in PHP because I want full control of my own code and no extra bagage from existing frameworks. Anyone who has any advice?


Yes, I've seen Lerdorfs article and it seems that it ain't so much code after all. Actually I would more like to have a controller-view solution for structuring my application. I'll stick to my own homemade PDO data-access classes.

Edit
Report

1 Answer

9

A simple exemple implementation of MVC (just to understand the principle)

MODEL: lib/Thing.class.php

class Thing
{
//class code ( CRUD, the application logic ...)
}

VIEW: theme/page_thing.php

<?php require("header.php");?>
//HTML CODE with some echo to show variables and loops to read arrays
<?php require("footer.php");?>

CONTROLLER: application/thing.php

require_once("lib/Thing.class.php");
/*
Some controls between the Model and the View ( if/else ...)
*/
include("theme/page_thing.php");
answered 2010-05-09T22:17:24.057

Your Answer