Download |
Bug Tracking |
Source |
Documentation |
Forum |
Latest Changes |
Home
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.
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:
<?php
include 'my_business_logic.php';
$product = false;
$error = false;
if (!empty($_GET['id'])) {
$product = get_product_by_id($_GET['id']);
if ($product == false) $error = 'The product was not found.';
}
?>
<html>
<title><?php if ($error): ?>We have an
error<?php else: echo $product['title']; endif; ?></title>
<body>
<?php if ($error) { echo $error; } ?>
<?php if ($product): ?>
echo product information.
<?php endif; ?>
</body></html>
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:
get_product_by_id function is in the my_business_logic.php file. 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:
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.
Pluf is good for you because it provides a clear and simple way to separate the three components which are in Pluf language:
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.
In fact, even Facebook is written that way, but it does not mean you should go that way... ↩
Report issues in the documentation
If you find errors or issues in the documentation, report a bug. We will update the documentation accordingly.
Pluf © 2005-2008 Loïc d'Anterroches, supported by Céondo Ltd.