Pluf Framework

Understanding-Pluf


You are looking at an old revision of the page Understanding-Pluf. This revision was created by Natalie Adams.

Table of Contents

Understanding Pluf and the dispatch loop

This is an introduction to Pluf to explain you why you would have an interest in using Pluf instead of bare metal PHP. First, I will present you the traditionnal way of writing applications with PHP and then the Pluf way.

Traditional Way to Write a PHP Application

In a traditionnal way, you will access a website written in PHP with this kind of URLs:

http://www.my-shop.com/index.php http://www.my-shop.com/products.php?id=12345

For each kind of functionnality in the website, you have one PHP script index.php, products.php. This script will process request variables for example the $_POST or $_GET variables, will have some kind of business logic and then echo back the results to the user.

This can be for the products.php example:

Page rendered in 0.03450s using 26 queries.

You can see that this is very simple and this is why PHP is so popular. It is extremely easy to drop a script.php in the document root of your webserver and get new functionnalities for your website. For that, PHP is great!

Now, if we analyse a little bit more this simple script, you can see that it is already well structured:

The logic with the get_product_by_id function is in the my_business_logic.php file. The first part of the script is having the interaction logic to handle the request. The second part of the script is outputing the webpage with the results. You can see a lot of websites written that way1. Now, if you work a little bit more, you can push the second part, that is, the presentation, in another file and just include it. That way you have a separation between the three different components:

  1. business logic;
  2. interaction logic;
  3. presentation of the results.

And this is good! But, there is a but. Of course, because without a but, no need to code a framework. When you do this separation, you will start to see that you will do the same things again and again, you will refactor, adapt the way you separate the components, and finally, you will end up writing your own framework.

So, the goal of a framework is just to help you structure your web application. Nothing more, and often, this simply means, a clear separation between the three components.

Why Pluf is Good for You?

Pluf is good for you because it provides a clear and simple way to separate the three components which are in Pluf language:

  1. business logic, the Models;
  2. interaction logic, the Views;
  3. presentation of the results, the Templates.

So Pluf is a MVT framework.

The dispatch loop will load the view matching the request. In the view, you will load and interact with your data models and render a nice page to the end user using templates.

By focusing on this clear goal, Pluf stays lean and fast and using it is nearly the same as coding the traditionnal way, but with the benefits of clear conventions, battle proofed methods to solve the basic interaction with data with an ORM or the templating system.

Created: 9 years 11 months ago
by Natalie Adams

Updated: 9 years 11 months ago
by Natalie Adams

Old Revisions

Page rendered in 0.03450s using 26 queries.