Application Configuration

Overview of configuration options for Nette Application.

Application

application:
	# show the "Nette Application" panel in Tracy BlueScreen?
	debugger: ...           # (bool) enabled if Tracy is available

	# in production, exceptions are always handled by the error-presenter;
	# this option only enables that behavior in development mode too
	catchExceptions: ...    # (bool) defaults to false - i.e. off in dev, always on in production

	# name of the error-presenter
	errorPresenter: Error   # (string|array) defaults to 'Nette:Error'

	# defines aliases for presenters and actions
	aliases: ...

	# defines the rules for translating the presenter name to a class
	mapping: ...

	# suppress warnings for invalid links?
	# effective only in development mode
	silentLinks: ...        # (bool) defaults to false

Since nette/application version 3.2, it is possible to define a pair of error presenters:

application:
	errorPresenter:
		4xx: Error4xx   # for Nette\Application\BadRequestException
		5xx: Error5xx   # for other exceptions

Splitting them is useful because both situations are fundamentally different. A BadRequestException (codes 4xx) means that the application is fine and only the visitor asked for something that does not exist. Therefore, you can use a full-featured presenter that displays a friendly message in the layout of your website. On the contrary, a 5xx error means that something in the application has broken and you do not know what. Keep the 5xx presenter as minimal as possible, so that nothing else can fail while rendering it – ideally, it should not touch the database, the layout, or the logged-in user.

The silentLinks option determines how Nette behaves in development mode when link generation fails (for example, because the presenter does not exist, etc.). The default value false means that Nette triggers an E_USER_WARNING error. Setting it to true suppresses this error message. In a production environment, E_USER_WARNING is always triggered. This behavior can also be influenced by setting the presenter variable $invalidLinkMode.

Aliases simplify referencing frequently used presenters.

The mapping defines the rules by which the class name is derived from the presenter name.

Automatic Registration of Presenters

Nette automatically adds presenters as services to the DI container, which significantly speeds up their creation. How Nette locates presenters can be configured:

application:
	# look for presenters in Composer class map?
	scanComposer: ...      # (bool) defaults to true

	# a mask that the class and file name must match
	scanFilter: ...        # (string) defaults to '*Presenter'

	# in which directories to look for presenters?
	scanDirs:              # (string[]|false) defaults to '%appDir%'
		- %vendorDir%/mymodule

The directories listed in scanDirs do not override the default value %appDir%, but complement it, so scanDirs will contain both paths %appDir% and %vendorDir%/mymodule. If we want to omit the default directory, we use an exclamation mark:

application:
	scanDirs!:
		- %vendorDir%/mymodule

Directory scanning can be turned off by setting the value to false. Presenters are then no longer registered as services, so they can't be adjusted via the decorator section and their creation is slower. We therefore do not recommend completely suppressing automatic registration, as it will reduce application performance.

Latte Templates

This setting globally affects the behavior of Latte in components and presenters.

latte:
	# show the Latte panel in the Tracy Bar for the main template (true) or for all components (all)?
	debugger: ...        # (true|false|'all') enabled if Tracy is available (debug mode only)

	# generate templates with declare(strict_types=1) header
	strictTypes: ...     # (bool) defaults to false

	# enable [strict parser mode |latte:develop#strict mode]
	strictParsing: ...   # (bool) default is false

	# limits the scope of variables to the loop body
	scopedLoopVariables: ... # (bool) default is false

	# removes indentation caused by nesting in paired tags
	dedent: ...          # (bool) default is false

	# enable [checking of generated code |latte:develop#Checking Generated Code]
	phpLinter: ...       # (string) default is null

	# set the locale
	locale: cs_CZ        # (string) default is null

	# class of the $this->template object
	templateClass: App\MyTemplateClass # defaults to Nette\Bridges\ApplicationLatte\DefaultTemplate

You can add new extensions using:

latte:
	extensions:
		- Latte\Essential\TranslatorExtension(@Nette\Localization\Translator)

Routing

Basic settings:

routing:
	# show the routing panel in Tracy Bar?
	debugger: ...   # (bool) enabled if Tracy is available (debug mode only)

	# serialize the router into the DI container
	cache: ...      # (bool) defaults to false

Routing is usually defined in the RouterFactory class. Alternatively, routes can also be defined in the configuration using mask: action pairs, but this method does not offer much flexibility:

routing:
	routes:
		'detail/<id>': Admin:Home:default
		'<presenter>/<action>': Front:Home:default

Constants

Creating PHP constants.

constants:
	Foobar: 'baz'

The Foobar constant will be created after the application starts.

Constants should not serve as globally available variables. To pass values to objects, use dependency injection.

PHP

Setting PHP directives. An overview of all directives can be found at php.net.

php:
	date.timezone: Europe/Prague

DI Services

These services are added to the DI container:

Name Type Description
application.application Nette\Application\Application the application runner
application.linkGenerator Nette\Application\LinkGenerator LinkGenerator
application.presenterFactory Nette\Application\IPresenterFactory presenter factory
application.### Nette\Application\UI\Presenter individual presenters
routing.router Nette\Routing\Router router
latte.latteFactory Nette\Bridges\ApplicationLatte\LatteFactory factory for Latte\Engine object
latte.templateFactory Nette\Application\UI\TemplateFactory factory for $this->template
version: 4.x 3.x 2.x