A micro PHP framework

Every time I begin to write an article it is so hard to start. So now Im going to keep it simple and straight. Lets see it.

I few days ago I started to work more seriously on a project, but it was quite interesting how to start it. I am familiarized with Symfony 2, but I consider it is a too heavy and big framework for what I want to use it. But it is too big to do it in plain PHP, its nonsense and I will end up in spaghetti code with lot of bugs and security holes and also will run slower than Symfony would do it.

I made my little research about using standalone Symfony components, and actually here is what have I done. A small, easy to overview and fast (theoretically,…) super-micro PHP framework which suits best my project I am working on (based of course on an MVC-ish pattern). You can find it on Github (https://github.com/fodor95/microphpframework). If you wish you can contribute to my code, I will be very thankful for that.

But now lets see the basic functionality of the code.

Loading Symfony HttpFoundation and HttpKernel for managing requests and routing, run the business logic than pass the result to a render engine. For templating I used Twig, because this is the template engine I like the most and also because it is one of the best template engines available I know about.

So the most basic usage of the framework is the following. You map your routes in the routes/routing.php file, in the method called routes():

$app->map('/map/your/route/{and_also_variable}', function ($name) {

global $twig;

$oldal = $twig->render('index.html', array('variable1' => 'value1', ....));

return new Response( $oldal ); (= "oldal" means page, its in Hungarian and will be fixed later)

The render method takes to arguments. The first is index. html the name of the template we want to render, these have to be placed inside the view folder and can be grouped in folders. The second is an array, here you can pass the results the controller generated. Controllers can be placed inside controllers folder, and an instance of them can be created using a kernel method called loadController(“controller_name”).

Basically that would be my micro php framework, but this is just an alfa version, later (in the near future) I will make some improvements, just follow my repo on Github.