Extras for nette/application
- Setup
- Application map
- Canonical link
- Form monitor
- Inspector
- Presenter mapping
- Short default action name
Install with Composer
composer require orisai/nette-applicationApplication map is a Tracy panel which lists all Nette presenters and their actions with corresponding links.
To use it, register extension:
extensions:
orisai.application.map: OriNette\Application\ApplicationMap\DI\ApplicationMapExtensionYou will also need to set up our reworked presenter mapping to make it work.
To show all presenters, their actions and links to them in Tracy panel, enable debug > panel option.
orisai.application.map:
debug:
panel: %debugMode%Generate canonical version of current url for better site indexing by webcrawlers.
Register service:
services:
- OriNette\Application\CanonicalLink\CanonicalLinker()Generate link to current page:
- without persistent parameters (of presenter and all components)
- without user-defined extra parameters
Don't do this for error presenter. It is not routable and generating link would fail.
use Nette\Application\UI\Presenter;
use OriNette\Application\CanonicalLink\CanonicalLinker;
abstract class BasePresenter extends Presenter
{
private CanonicalLinker $canonicalLinker;
final public function inject(CanonicalLinker $canonicalLinker): void
{
$this->canonicalLinker = $canonicalLinker;
}
public function beforeRender(): void
{
parent::beforeRender();
$this->template->canonicalLink = $this->canonicalLinker->linkForPresenter($this);
}
}Render HTML tags for unique url:
<meta property="og:url" content="{$canonicalLink}">
<link rel="canonical" href="{$canonicalLink}">Optionally, specify additional unwanted params:
services:
- OriNette\Application\CanonicalLink\CanonicalLinker(['do'])Form monitor is a Tracy panel which lists all errors from a submitted
form (Nette\Application\UI\Form).
To use it, register and enable extension:
extensions:
orisai.application.formMonitor: OriNette\Application\FormMonitor\DI\FormMonitorExtension
orisai.application.formMonitor:
enabled: %debugMode%
debug:
panel: %debugMode%Inspector is a Tracy panel which lists all Nette components with useful info and enables visual debug of these rendered via Latte.
To use it, register and enable extension:
extensions:
orisai.application.inspector: OriNette\Application\Inspector\DI\InspectorExtension
orisai.application.inspector:
enabled: %debugMode%Overwrite default presenter factory for:
class-string<IPresenter>to presenter name mapping (required by application map)- mapping of each presenter individually
extensions:
orisai.application.presenterFactory: OriNette\Application\Mapping\DI\PresenterFactoryExtensionChange also presenter factory callback to make sure all presenters are registered as services:
orisai.application.presenterFactory:
presenterConstructor: 'strict'Use methods action() and render() instead of actionDefault() and renderDefault()
use Nette\Application\UI\Presenter;
+use OriNette\Application\Presenter\ShortDefaultActionName;
abstract class BasePresenter extends Presenter
{
+ use ShortDefaultActionName;
- public function actionDefault(): void
+ public function action(): void
{
}
- public function renderDefault(): void
+ public function render(): void
{
}
public function actionOther(): void
{
}
public function renderOther(): void
{
}
}