PHP code example of drago-ex / simple

1. Go to this page and download the library: Download drago-ex/simple library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

drago-ex / simple example snippets


use Drago\Simple\Base\Session;

// Get session instance
$this->session();

use Drago\Simple\Base\Message;

// Save message to session
$this->flashMessage('Message...');

// Retrieve flash message from session
$this->getFlashMessage();

use Drago\Simple\Base\Response;

// Redirect to a URL
$this->redirect('#');

final class Home
{
    private Latte\Engine $latte;

    public function __construct(Latte\Engine $latte)
    {
        $this->latte = $latte;
    }
}

public function render(): void
{
    $this->latte->render(__DIR__ . '/path/to/dir/template.latte');
}

public function render(): void
{
    $this->flashMessage('message...');
    $message['message'] = $this->getFlashMessage();
    $this->latte->render(__DIR__ . '/path/to/dir/template.latte', $message);
}

$latte->onCompile[] = function () use ($latte) {
	FormMacros::install($latte->getCompiler());
};

private array $lang = ['en', 'cs'];

$translator = new Translator(__DIR__ . '/locale');
$translator->setTranslate((new RequestFactory())->fromGlobals()
	->detectLanguage($this->lang)
);

$latte->addFilter('translate', function ($message) use ($translator) {
	return $translator->translate($message);
});