Fat-Free Framework – 1. Installing Fat-Free Framework (with Composer)

Created at: October 6, 2016; Last update: October 7, 2016

In order to install Fat Free Framework, we don’t need composer, but it is a good idea to use composer because we need to think about the good things coming from it, like loading additional libraries, or updating the framework and/or libraries.

So let us create a directory inside our public server directory (public_html, htdocs or whatever…). Inside it we will put a composer.json file:

Of course, you can change whatever you like in here as long as you leave the required element named bcosca/fatfree:

You can also create a composer.json file from nothing with the help of the composer command line by going with the terminal (console) where your directory is and typing:

…and follow the required steps.

Once you done that, if you don’t have the terminal opened at that location
of the composer.json file (inside the directory where you want to install the framework), do it now…

And do a:

Once composer finished you should have a copy of the framework inside the vendor directory.

Now let’s create an index.php file inside the parent directory (the public directory) in order to test the correct install of the framework.

In order to make sure the files are loaded, we need to require the autoload.php:

Once we’ve done that, we need to create an instance of the framework and run it:

Now… if we run we should see something on the lines of this:

Internal Server Error

No routes specified

Cool. We’re done! “WAAAAAIT!!! THAT IS AN ERROR!”, you might yell. Well… Even an error is a sign of a program working. Anyway, let’s add a route, to see if it really works or not:

Let’s see the index.php in its entirety:

Now if you visit the page from your browser you should see something changed… Now we’re done? By the way… GREAT TUTORIAL HERE: https://www.youtube.com/playlist?list=PLX0Ak4vUBQfClFDicUaSfm-urMi_kt3cg

2 thoughts on “Fat-Free Framework – 1. Installing Fat-Free Framework (with Composer)

  1. RHF

    Adrian,
    Thank you for you many fine tutorials, especially on the use of CodeIgniter.
    Your article on Fat-Free Framework, which I had never tried before, prompts me to ask a few questions:
    1. The CodeIgniter forum for Version 4 indicates that V.4 will require complete code re-writes. Does it make sense to commit a lot of time using V.3 for a major new project?
    2. Some of the CI features, such as form validation rules for example, can be handled with HTML 5 and JavaScript. Is it not more efficient (and only slightly harder) to use these client-side methods when available?
    3. For someone reasonably competent in writing PHP code and MySQL queries, do you think that the Fat-Free Framework might be a better choice for long-term stability? (I realize there is no definitive answer to this, but I am interested in your general opinion.)
    Thanks,
    RHF

    Reply
    1. avenirer Post author

      It is like you’ve read my mind with this comment. To be honest, I don’t know what the future holds for CodeIgniter. I am a bit scared about version 4, as it will change a lot of my way of writing code. I am confident that in the end it will still be a strong framework. Regarding your questions:
      1. When creating a new project it is important for you to feel comfortable with the code you’re using. Considering that version 4 will most likely be out in middle 2017, I would wait for it to appear. If you don’t have time to wait, I would advise you to use version 3, as this is a stable version and is still easy to use. You can also combine the framework with composer packages, which is a viable way of continuing to develop in the future.
      2. Indeed, it is advisable from a “speed” point of view to validate data client-side (because this way you make sure that the necessary data will be taken from the form without needing to reload pages), but in no way this excludes server-side validation.
      3. For “someone reasonably competent in writing PHP”, the best of the best solution would be to use no framework at all. Fat-Free Framework is the closest thing to a “no frame at all” idea, but the thing is that when using no framework or even F3 you will find yourself in front of a blank page… And this is scary… CodeIgniter on the other hand has almost everything you need, so you won’t have to think too much in order to put a website online. You should find an equilibrium between the time you can afford to spend and the task you have to do.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

No spam? * Time limit is exhausted. Please reload CAPTCHA.