drago-ex / simple
Easy configuration for single-page sites.
v1.0.11
2025-01-27 06:11 UTC
Requires
- php: >=8.3 <9
- latte/latte: ^3.0
- nette/http: ^3.0
- nette/robot-loader: ^4.0
Requires (Dev)
- nette/tester: ^2.5
- phpstan/phpstan-nette: ^1.2.9
- tracy/tracy: ^2.10
README
Easy configuration for single-page sites.
Technology
- PHP 8.3 or higher
- composer
Knowledge
- Latte: amazing template engine for PHP
- RobotLoader: comfortable autoloading
- Nette HTTP Component
- Tracy - PHP debugger
Installation
composer require drago/simple
Traits
Session Trait
use Drago\Simple\Base\Session; // Get session instance $this->session();
Message Trait
use Drago\Simple\Base\Message; // Save message to session $this->flashMessage('Message...'); // Retrieve flash message from session $this->getFlashMessage();
Response Trait
use Drago\Simple\Base\Response; // Redirect to a URL $this->redirect('#');
Controller Example
final class Home { private Latte\Engine $latte; public function __construct(Latte\Engine $latte) { $this->latte = $latte; } }
Template Rendering
public function render(): void { $this->latte->render(__DIR__ . '/path/to/dir/template.latte'); }
Passing Parameters to Templates
public function render(): void { $this->flashMessage('message...'); $message['message'] = $this->getFlashMessage(); $this->latte->render(__DIR__ . '/path/to/dir/template.latte', $message); }
Template: Print Message
<p n:if="$message">{$message}</p>
Template: Default Parameter for Include Files
{$basePath}
Forms
Install Nette Forms via Composer:
composer require nette/forms
Forms Latte Macro
$latte->onCompile[] = function () use ($latte) { FormMacros::install($latte->getCompiler()); };
Translator
Install the Translator via Composer:
composer require drago-ex/translator
Translator Property
private array $lang = ['en', 'cs'];
Translator Language Detection
$translator = new Translator(__DIR__ . '/locale'); $translator->setTranslate((new RequestFactory())->fromGlobals() ->detectLanguage($this->lang) );
Translator Latte Filter
$latte->addFilter('translate', function ($message) use ($translator) { return $translator->translate($message); });