ToroPHP - A Tiny PHP Framework
toroweb.org
toroweb.org
Let's see how I build my website
require_once 'path/to/F3.php';
F3::route('GET /','home');
function home() {
echo 'Hello, world!';
}
F3::run();Nice, no? This help me start quickly, iterate rapidly and scale easily when the project gets bigger by dividing and expanding the small parts.
- You chose your own directories structure
- No .htaccess hacking needed.
- Own variables table
- Lot of useful plugins, like a lightweight ORM, Form Handler, Unit Testing, Very flexible Caching
- You decide to use OOP, MVC, procedural programming... or a combination of your choice
- Really lightweight: 50kb
Just a minor complaint about the dispatcher syntax:
Array('^\/article\/([a-zA-Z0-9_]+)\/?$', 'regex', 'ArticleHandler')
Those backslashes look clunky. Something as commonly used as a forward slash in a URI shouldn't need to be escaped. Quick fix: use something else as a delimiter, such as #, in line 45. (It should be a character that never occurs in a valid URI on the server side. # is a reasonable choice because the fragment never gets passed to the server.)I like it though. Thanks for the tip!
Hello World using GluePHP:
<?php
require_once('glue.php');
$urls = array(
'/' => 'index'
);
class index {
function GET() {
echo "Hello, World!";
}
}
glue::stick($urls);
?>
Another example with parameter matching and POST method handling: <?php
require_once('glue.php');
$urls = array(
'/' => 'index',
'/(?P<number>\d+)' => 'index'
);
class index {
function GET($matches) {
if (array_key_exists('number', $matches)) {
echo "The magic number is: " . $matches['number'];
} else {
echo "You did not enter a number.";
}
}
function POST() {
echo 'The value you entered was ' . $_POST['textbox1'];
}
}
glue::stick($urls);
?>index.php: <? echo 'hello, world'; ?>
It's really simple and small.. almost non-existent.