Search by

drago-ex / application

accgit

Extension for Nette Framework, providing reusable UI components, alert types, and flash message handling.

Package info

github.com/drago-ex/application

pkg:composer/drago-ex/application

Statistics

Installs: 5 823

Dependents: 12

Suggesters: 0

Stars: 0

Open Issues: 0

v5.0.1 2026-11-17 10:27 UTC

README

Base classes for Nette controls, templates and form factories, and flash message types.

License: MIT PHP version Tests Coding Style

Requirements

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

Installation

composer require drago-ex/application

ExtraControl

Extend Drago\Application\UI\ExtraControl instead of Nette\Application\UI\Control.

AJAX request

Shortcut for the presenter check:

$this->isAjax();

Presenter helpers

These methods call the corresponding presenter method, so they are useful when an action should affect the whole page rather than only the control.

$this->addRedirect('Homepage:default'); // Redirects the presenter.
$this->addRedraw('content'); // Marks a presenter snippet for redraw (null redraws all snippets).
$this->addFlashMessage('Changes saved.', 'success'); // Adds a presenter flash message.

Translator

The control translates its template and translate() with the translator of the presenter (getTranslator(), which drago-ex/translator adds), so a control needs no wiring. Set the public $translator property only for another translator than the one of the presenter. Without any translator the control works too: its template prints the texts unchanged and translate() returns the message as-is or formats its parameters with vsprintf().

$label = $this->translate('Hello %s', $name);

Form component by name

Returns the form control, or null when the component is not a form control (for example a container):

$form = $this['factory'];
$submitButton = $this->getFormComponent($form, 'submit');
$submitButton->setCaption('Edit');

Form Factory

Drago\Application\UI\Factory creates forms with the translator set (autowired). Extend it for a typed factory of another form class, for example ExtraForms from drago-ex/form:

use Drago\Form\ExtraForms;

/**
 * @extends \Drago\Application\UI\Factory<ExtraForms>
 */
readonly class Factory extends \Drago\Application\UI\Factory
{
	protected function createForm(): ExtraForms
	{
		return new ExtraForms;
	}
}

ExtraTemplate

A base template class with the variables Nette passes to every template ($presenter, $control, $user, $baseUrl, $basePath, $flashes).

Use it in presenter or control PHPDoc:

/**
 * @property-read Drago\Application\UI\ExtraTemplate $template
 */
class Presenter {}

In Latte, declare the template type and the flash messages:

{templateType Drago\Application\UI\ExtraTemplate}
{varType Drago\Application\UI\Flashes[] $flashes}

Flash message alert types

Drago\Application\UI\Alert defines Success, Danger, Warning and Info:

$this->flashMessage('Saved.', Alert::Success);