Search by

drago-ex / simple

accgit

Easy configuration for single-page sites.

Package info

github.com/drago-ex/simple

pkg:composer/drago-ex/simple

Statistics

Installs: 203

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v3.0.0 2026-10-29 15:27 UTC

This package is auto-updated.

Last update: 2026-10-31 06:49:02 UTC


README

Easy configuration for single-page sites.

License: MIT PHP version Tests Coding Style

Requirements

  • PHP >= 8.3, < 9
  • Nette Framework
  • Composer

Installation

composer require drago-ex/simple

Knowledge

Latte

Drago\Simple\Latte is a Latte engine that passes $basePath to every template:

use Drago\Simple\Latte;

$latte = new Latte;
$latte->setTempDirectory(__DIR__ . '/../temp/latte');
<link rel="stylesheet" href="{$basePath}/css/style.css">

Traits

Session Trait

use Drago\Simple\Base\Session;

// The session is created from the current request on the first call and then reused
$this->session();

Message Trait

use Drago\Simple\Base\Message;

// Save a message for the next page
$this->flashMessage('Message...');

// Read the message; it is removed after reading, so it is shown only once
$this->getFlashMessage();

Response Trait

use Drago\Simple\Base\Response;

// Redirect to a URL; the script stops after the redirect is sent
$this->redirect('#');

Controller Example

use Drago\Simple\Base\Message;
use Drago\Simple\Latte;

final class Home
{
	use Message;

	public function __construct(
		private Latte $latte,
	) {
	}


	public function render(): void
	{
		$this->latte->render(__DIR__ . '/templates/Home.latte', [
			'message' => $this->getFlashMessage(),
		]);
	}
}
<p n:if="$message">{$message}</p>

Forms

Install Nette Forms via Composer:

composer require nette/forms

Register the form tags in Latte:

$latte->addExtension(new \Nette\Bridges\FormsLatte\FormsExtension);

Translator

Drago\Simple\Translator reads the messages of one language from a PHP file returning an array:

// locale/cs.php
return [
	'Hello' => 'Ahoj',
	'Hello %s' => 'Ahoj %s',
];

Choose the language from the request and register the translator in Latte:

use Drago\Simple\Translator;
use Nette\Http\RequestFactory;

$lang = (new RequestFactory)->fromGlobals()->detectLanguage(['en', 'cs']) ?? 'en';
$translator = new Translator(__DIR__ . '/locale', $lang);

$latte->addExtension(new \Latte\Essential\TranslatorExtension($translator));

Translations are then available in templates as {_'Hello'}, {_'Hello %s', $name} or {$text|translate}; a message without a translation is shown as it is. Every language needs its file (locale/en.php may return []), otherwise the translator throws an exception. It also works as the translator of Nette Forms.

Prepared Package for Simple Project

https://github.com/drago-ex/simple-project