1. Go to this page and download the library: Download yahyamallak/masar library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yahyamallak / masar example snippets
use Masar\Exceptions\NotFoundException;
use Masar\Http\Request;
use Masar\Routing\Router;
$router = new Router();
// Define routes
$router->get('/', function() {
return "Welcome to the homepage!";
});
$router->get('/about', function() {
return "About us page";
});
$router->post('/submit', function() {
return "Form submitted";
});
$router->put('/users/{id}/change', function($id) {
return "User " . $id . " has been edited.";
});
$router->patch('/users/{id}/edit', function($id) {
return "edit name of user : " . $id;
});
$router->delete('/users/{id}/delete', function($id) {
return "delete user " . $id;
});
// Create a request object
$request = new Request();
// Dispatch the router
try {
$router->dispatch($request);
} catch (NotFoundException $e) {
echo $e->getMessage();
}
$router->get('/user/{id}', function($id) {
return "User profile for user with ID: " . $id;
});
$router->get('/post/{slug}', function($slug) {
return "Displaying post: " . $slug;
});
$router->get('/user/{id}', function($id) {
return "User profile for user with ID: " . $id;
})->where(["id" => ":number"]);
$router->get('/users', function() {
return "All users.";
})->name("users");