Example #1 description
<?php require '../vendor/autoload.php';
use BearFramework\App;
// Constructs a new Bear Framework application.
$app = new App();
$app->routes
->add('/', function() { // Defines a handler for the application home page.
$response = new App\Response(); // Constructs a new response.
$response->content = 'This is the home page!'; // Sets the response content.
return $response; // Returns the response.
})
->add('/products/', function() { // Defines a handler for a request with a path matching "/products/"
$response = new App\Response(); // Constructs a new response.
$response->content = 'This is the products page!'; // Sets the response content.
return $response; // Returns the response.
})
->add('/products/?/', function(App\Request $request) { // Defines a handler for a request with a path staring with "/products/" followed by one more path segment.
$productSlug = $request->path->getSegment(1); // Retrieves the value of the second segment.
$response = new App\Response(); // Constructs a new response.
$response->content = 'This is the page for ' . $productSlug . '!'; // Sets the response content.
return $response; // Returns the response.
});
// Finds the response and send it to the client.
$app->run();
Location: ~/examples/Routes.php