Skip to content

drago-ex/simple

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Drago Simple

Easy configuration for single-page sites.

License: MIT PHP version Tests Coding Style CodeFactor Coverage Status

Technology

  • PHP 8.1 or higher
  • composer

Knowledge

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);
});

Prepared package for simple project

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