Fat-Free Framework – 8. Using the templating engine of the framework

Created at: October 21, 2016; Last update: October 21, 2016

Even though it’s a tiny framework, Fat-Free has a templating engine that we can use. In order to do this, instead of calling the View class, we call the Template class:

But what can we do with this template engine? Well… Besides the fact that it’s faster to work with it, it is also safer (or at least “they say” it is). Continue reading

Fat-Free Framework – 7. Enter the Views. How to separate logic from presentation in F3

Created at: October 21, 2016; Last update: October 21, 2016

Up until now we’ve done our tests by echoing to the browser window the variables. Of course, this was only to do our tests and to see if what we do is ending well or not.

But now we should talk about the Views in MVC. Do you remember the global variables that Fat-Free Framework is using extensively in what it names the Hive? Well… Among these global variables there exists one named UI (from user-interface?). This variable tells the framework where it can find the views in case these views are called. Continue reading

Fat-Free Framework – 5. Returning to routes and how to work with them

Created at: October 13, 2016; Last update: October 13, 2016

Fat-Free Framework has a good routing engine. So let’s see what we can do with it.

For starters let us assume that the contact page would need to receive a parameter yoursite.com/contact/avenirer

If you visit that address you should get a nice 404.

How do we get that “avenirer” part inside our method, and not be redirected to a 404? Continue reading

Fat-Free Framework – 4. Moving the Routes in a file

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

In the previous tutorial (Fat Free Framework – 3. Creating a configuration file) we learned about configuration files, and how to import them into our app. Let’s look into our main index.php:

As you can see we have a route defined in there, which tells our app that when someone tries to access the homepage, it should serve the Homepage controller with its index() method. Continue reading

Fat-Free Framework – 3. Creating a configuration file

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

In the previous tutorial (Fat Free Framework – 2. Moving logic to controllers), we moved the Homepage controller inside the App/Controllers directory. In order to tell the framework we did this, we’ve set a variable called “AUTOLOAD” to point to that particular directory:

AUTOLOAD is one of many global variables, that is “the variables used by the framework globally”. F3 is allowing us to change those variables by using the set() method inside our php scripts. Read more about the global variables here: https://fatfreeframework.com/framework-variables#Globals

Of course we can keep the configuration things inside the main index.php and/or wherever else we like, but we can also use a configuration file. What this file does is keep the configuration variables in an easy to read format, so instead of creating a lot of lines that start with $f3->set(‘variable’,’value’); we can have a nice looking file where everything has its own place.

So let us create a setup.cfg file inside our App/Config directory, and move the AUTOLOAD global variable inside it:

Once we did this we only need to tell the main index file to retrieve the configuration data from that specific file, instead of setting the AUTOLOAD global. So let’s see our main index.php modified:

And since we are working with the configuration file, why not also set the debug level to 3, as this will offer us a lot of details when there is an error on our application.

Let’s see how our setup.cfg looks like:

And… just to be sure that we did all we can so no one can see our configuration files (although we will also move the App directory outside the public directory, later), let’s create a .htaccess file and put it inside our App:

Put an Enter after that line, and save it. Nice. In the next tutorial we will learn more about the configuration files and also move the routes in one such config file.

Fat-Free Framework – 2. Moving logic to controllers

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

In the previous tutorial (Fat Free Framework – 1. Installing Fat Free Framework…), we tested the installation of Fat Free Framework by creating a route that was calling an anonymous function when someone was accessing the application:

But if we do this for every “page” that someone access the main index.php file would become pretty large soon. Continue reading

Fat-Free Framework Tutorials

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

Here you should see some Fat-Free Framework tutorials. These are only what I understood from other tutorials. This is not a “copy/paste” series. It is everything I tested and liked.

But before my tutorials, you will see some resources that I used in order to learn more about this framework:

https://www.youtube.com/watch?v=R-ydcTTrR5s&list=PLX0Ak4vUBQfClFDicUaSfm-urMi_kt3cg

Now to my tutorials…

Back to (PHP) basics. Creating your own SEO friendly “mini-website” in PHP

Created at: May 27, 2016; Last update: August 12, 2016

I want to be noted that this is not a tutorial about creating an MVC framework from zero. If you want that kind of tutorial, you can find a lot of them (https://www.youtube.com/playlist?list=PLfdtiltiRHWGXVHXX09fxXDi-DqInchFD https://www.youtube.com/playlist?list=PL7A20112CF84B2229).

There are moments in your programmer life when you are asked to do a small “landing page”, which actually turns out to be a “mini-website” with an “About” page, a “Contact” page and a few other pages. Continue reading