Skip to content

Routing

Champa edited this page Jul 15, 2017 · 3 revisions

Fasty - the fast and simple PHP framework

Routing

Fasty uses a simple routing system based on symfonys http components
It supports both a closure call or a controller::method combo

To create a route, navigate to ~/routes

Routing to closures

Open GetRoutes.php and add the following

$this->get('/', function() {

    return 'Hello world!';
});

Lets say we have a domain called fasty.com
With these 3 lines of code, we've added a route to the root of fasty.com with a message saying "Hello world!"

Routing to controllers

Routing to controllers is a bit bit more difficult because you need to edit two files - the .routes.php and a controller file

Open up GetRoutes.php and add the following

$this->get('/', 'Web@index');

Next, create a file named web.php in the ~/controllers folder with the following content

<?php
class Web
{
    public function index() {

        return 'Hello world!';
    }
}
?>

Navigate to your domain and you should see a "Hello world!" message

Next

Displaying views using Fasty's template engine

Clone this wiki locally