drago-ex / simple
Easy configuration for single-page sites.
v1.0.10
2023-12-01 10:56 UTC
Requires
- php: >=8.1 <8.4
- latte/latte: ^3.0
- nette/http: ^3.0
- nette/robot-loader: ^3.2
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.1 or higher
- composer
Knowledge
- Latte: amazing template engine for PHP
- RobotLoader: comfortable autoloading
- Nette HTTP Component
- Tracy - PHP debugger
Installation
composer require drago/simple
Trait Session
use Drago\Simple\Base\Session // Get session. $this->session();
Trait Message
use Drago\Simple\Base\Message; // Save message. $this->flashMessage('Message...'); // Print message. $this->getFlashMessage();
Trait Response
use Drago\Simple\Base\Response; $this->redirect('#');
Controller
final class Home { private Latte\Engine $latte; public function __construct(Latte\Engine $latte) { $this->latte = $latte; } }
Template render
public function render(): void { $this->latte->render(__DIR__ . '/path/to/dir/template.latte'); }
Template passing parameters
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 via composer.
composer require nette/forms
Forms latte macro.
$latte->onCompile[] = function () use ($latte) { FormMacros::install($latte->getCompiler()); };
Translator
Install via composer.
composer require drago-ex/translator
Translator property.
private array $lang = ['en', 'cs'];
Translator language detect.
$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); });