Lemonade in practice.
Concrete uses of routing, controllers, services, middleware, views, JSON APIs, localization, and CLI commands in application code.
Selected example
01 / Routing
Route definitions, HTTP methods, URL parameters, and controller actions.
Open exampleapp/Config/Routing.phpPHP
<?php
declare(strict_types=1);
use App\Controllers\ArticleController;
use Lemonade\Framework\Routing\ControllerAction;
use Lemonade\Framework\Routing\Router;
return static function (Router $router): void {
$router->getNamed(
'articles.detail',
'/articles/{id}',
ControllerAction::for(ArticleController::class, 'detail'),
);
};In this file
Routing.php returns a callback that receives the router. The named GET route maps /articles/{id} to ArticleController::detail().
- a GET route for /articles/{id}
- passing the id parameter to the action
- binding the controller through ControllerAction::for()
02 /ControllersA controller is a PHP class created in Request scope. It receives dependencies through its constructor and may return a PSR-7 response directly.03 /JSON APIResponses::json() encodes data as JSON and returns a PSR-7 response with the selected HTTP status and content type.
More topics
Explore more examples.
Services, middleware, views, localization, and CLI each have their own steps and source files.
04 /Service providersService bindings, container configuration, and dependencies between services.05 /MiddlewarePSR-15 middleware, request forwarding, and response handling.06 /Views and formsRendering PHP views, forms, input validation, and CSRF protection.07 /LocalizationTranslation catalogs, localized URLs, and translations in views.08 /Installation and CLIComposer installation, application layout, and custom CLI commands.