I, too, wrote an homegrown MVC framework in PHP. Its pretty simple, especially when you remove any "ActiveRecord" functionality from your frame work. Some things that I considered:
How are you going to map URLs to controllers?
Instead of doing things by convention (/foo maps to FooController), I did everything via configuration. That is, I have a master routes.php file wherein I list every possible URL that my application will accept. So its filled with things like:
Router::add( '/foo/:Param1/:Param2',
array( 'Controller' => 'MyController',
'Action' => 'my_method',
'Method' => 'GET',
'Parameters' => array( 'Param1' => '\d+',
'Param2' => '\S+' ) );
In this case we match urls like /foo/123/abc
. When the URL is matched, it is dispatched as MyController::my_method( array( 'Param1' => '123', 'Param2' => 'abc' ) );
.
How are you going to generate views?
There are lots of templating systems out there. But really, PHP is already a perfect templating system. In my framework, I just created a function template()
in the top-level Controller
class. And it all boils down to performing an include $Template
. Again, in my framework, there is no convention. Each controller is responsible for instantiating the appropriate template, and for understanding if the request is expecting HTML, XML, or JSON as a response.
Can you use an existing framework?
A lot of my code was inspired by Cake, the well-known PHP MVC framework. I'd definitely take a peek at it before you proceed to far. If you're going to roll your own, at least start by understanding how all of the popular ones work. In the end, the peculiar requirements of my application made me go down the road of build my own, but there was a lot to be learned from all the frameworks already out there. Take a long look around, and you may find something that works for you. At the very least, you may figure out exactly what you need out of your framework.