PHP and MySQL

Fat-Free Framework Review

Posted on Sunday, September 19th, 2010 by Jesse


I don’t care too much for bloated frameworks, so I find myself looking at the ones everybody dismisses or ignores. Fat-Free Framework is one I crave of finding to learn something different.

What is it?

It’s the first PHP 5.3 framework to be out of the beta stage and can be used in production. It’s also the first framework I’ve seen that uses a single static class in a single file. What does this mean? I no longer have to make sure all files are in sync with the newest version? Yup! It also makes it easier to place the file where you need to so it’s out of the way from your application.

I mentioned that it’s a static framework in which you no longer have to extend your classes to the Model class or Controller class etc. Instead when you need to use the framework to perform an action you do so like any other static class: F3::StaticMethod. Let’s look at an example.

What makes it stand out?

The first thing everyone will notice is the way routes are used. For example, this is how you would set up a route:

<?php
     //index.php
     require_once 'F3.php';
 
     F3::route('GET /','example');
 
     function example() 
     {
          echo 'Hello, world!';
     }
 
     F3::run();
?>

You notice that you have to predefine your routes, unlike other frameworks. In this case, I have a route set up at http://website.com/ This is done with the route method and using the keyword GET with a forward slash. If I were to change that slash to say /hello then whenever someone went to http://website.com/hello, the example function would be called- this is the second parameter. In this case, only one function is being called which would echo “Hello, world!”. None of this would be executed until the run method is called at the end of the file as shown.

Another thing that is not normal is the fact there is no right way to set up your application. You no longer have to follow the MVC pattern, although you should. This makes it easy to develop your application without worrying about how to follow the framework standards. With this in mind, a lot of programmers may not like being so free as it is easy to not even follow your own standards or even remember them. My solution was to follow the MVC pattern, so that not only I could understand later, but anyone else could too.

Take a look at the 52 pages of content at the site on SourceForge, for more.

Should It Be Used?

I have created an application with the following features: blog, flood control, support tickets, and user database. It is very possible to create a production application using this framework. The hardest part was to come up with how to follow the MVC pattern when a lot of things are different. This took at least 50% of the time I spent with the framework to create the application.

Even though the creator himself states that this is the easiest framework to use, I have to disagree. It may be easy for a simple website, but when you’re talking about production quality, I don’t think it has the power. Mostly because of the lack of dynamic routes and no standards whatsoever it would be impossible to maintain to future programmers.

Luckily, I was able to overcome most of the issues. I still think it’s not ready for prime time, but don’t stop yourself from learning something new! Spend some time with it and you’ll better understand how to use patterns and realize how important making maintainable code really is. Have Fun!

10 Responses to “Fat-Free Framework Review”

  1. Meshach says:

    Thanks for this review, Jesse. Really helpful. Do you have any of the code you used to follow the MVC pattern available publicly? I’m about to begin a small prototype project with F3, and with such little sample information out there, I thought I’d ask directly.

    Thank ahead of time.
    Meshach

  2. Jesse says:

    Hi Meshach,

    Unfortunately, I have not been able to keep up with the Fat Free Framework. For work, I’ve been using the Kohana Framework. However the framework is still great for small projects that (when I have time) will use in the future. However, I almost have a complete application with the F3 framework. It may not be the best form, but it may give you a few examples. I’ve sent the application to your email from your comment. If more people request the code, I’ll post it publicly.

    You may use the code as you wish, no need to pay for it or anything :)

  3. Julius says:

    Thank you for publishing this review! I would, too, be grateful if you could send/publish your F3 code. It would be great to have some more F3 samples available. Thanks in advance!

  4. Steve says:

    Please email the code to me also.

    What version number did you use for this review?

    And what did you feel in it was not ready for production?

  5. Hey Jesse!

    I would also be interested to look at your sample F3 application.

    Thanks a lot!

  6. Jesse says:

    Hey Guys,

    After writing this comment I’ll send out the code, it doesn’t include the database scheme only because I have since deleted the database, so it wont be plug-in-play.

    I decided it wasn’t production level only because I needed a framework with a defined set of rules. Having too much freedom made it difficult to set a clear set of rules that can’t easily be based on MVC. This may be possible now, but I’d rather just use a a framework with MVC as the standard.

    This doesn’t mean the framework is a waste of time, instead it was great being able to throw together a website quickly without having to do much configurations. This would be great for a quick prototype to show a client what you’re thinking and such.

    I have now moved on to Kohana3 for production level applications. It may be bulky for simple and dirty applications, but for a large scale program it’s barely noticeable.

  7. Lydia says:

    Fat-Free Framework 2.0 has just been released. It’s packed with new exciting features, outstanding documentation and improved overall performance. This new version of F3 (as it’s fondly called) still retains its lightweight 55KB footprint and remains true to its promise of being easy to use even for novices, yet stable and powerful enough to run high-traffic Web sites.

  8. Jesse says:

    Thanks Lydia. I’ll have to take a look into it.

  9. thompson says:

    I’m not sure what you mean by ‘dynamic routes’ (I’m new to frameworks). But I know at least in Fat Free 2.0.3, it has allowed me to do /slug/#### by using:

    F3::route(‘GET /question/@question_id’,'questions’);
    function questions() {
    echo F3::get(‘PARAMS["question_id"]‘).’ = question id #.’;
    // then add code to get the template here
    }

    And then you can pass that # (presumably an id of some type of content) into your php view & classes.

    I know this post was written a while ago when F3 was in v1x. But, is that what you mean by dynamic routing?

    I looked at symfony2 and Yii, but those were overwhelming to me. Fat Free was the first framework that clicked with me and seems as easy as a framework should be. But maybe I should take a look at Kahona too.

  10. Esteban says:

    Hello, I’m testing f3 myself, it would be nice to see your app so I can have some reference.

    Thanks.

Leave a Reply