Improve this page
You are browsing the unmaintained documentation for old Nette 2.3. See documentation for current Nette.

Configuration

Configuration is usually written in NEON format. Have fun trying out the syntax at https://ne-on.org. Many features of Nette Framework can be set up in configuration file.

HTTP proxies

You can define your http proxy, so that HTTP request's remote address and remote host will be correct.

http:
	proxy: 127.0.0.1  # ip address, range, hostname or array of these values

Sessions

Here you can set all directives (in camelCase format).

session:
	autoStart: true  # default is smart
	expiration: 10 days
	name: ...
	...

autoStart: smart is recommended. It automatically starts the session only if it already exists.

Read more on session configuration.

Application

application:
	debugger: true  # debugger bar panel
	catchExceptions: %productionMode%
	errorPresenter: Front:Error
	mapping:  # mapping between presenter name and presenter class
		Front: App\*Module\*Presenter

errorPresenter

Default value: Nette:Error

This parameter specifies the presenter which is invoked when an error occurs. We can find an example in the sandbox.

If an error has occurred while the error presenter is being executed, Tracy will show only a simple error page.

catchExceptions

Default value: TRUE in production mode, FALSE in debug mode

This parameter decides if the error presenter will be invoked. By changing this value to TRUE in the debug mode we can test functionality of the error presenter.

mapping

Default value: *: *Module\*Presenter (in the sandbox *: App\*Module\Presenters\*Presenter)

This parameter contains an array with rules for converting presenter name to the class name. In the key we define a module name or * as a fallback for other modules. The value contains the rule mask:

application:
	mapping:
		Admin: App\Admin\*Module\*Presenter
		*: App\*Module\Presenters\*Presenter

The presenter Front:Blog:Article is contained inside the Front module. Since this module has no explicit mapping, the mapping with asterisk will be used and the class will be called App\FrontModule\BlogModule\Presenters\ArticlePresenter. The presenter Admin:User:Edit is part of the Admin module which has separate mapping so the name of the presenter class will be App\Admin\UserModule\EditPresenter (note that since the Admin is already in the mapping definition, it will be stripped from the resulting class name).

Default value: FALSE

This option specifies Nette behaviour in the debug mode when a link generation fails. With FALSE value Nette will trigger E_USER_WARNING. Changing this configuration option to TRUE will suppress this error. In production environment, E_USER_WARNING will be always triggered.

We can also adjust this behaviour using class property Presenter::$invalidLinkMode.

scan*

Nette allows automatic registration of presenters as services. This step improves presenter creation speed. There are few configuration options that adjust where and how Nette looks for them.

scanDirs

Default value: %appDir% (/app)

This value contains an array with directories where Nette looks for the presenters. If we specify another value in the configuration, it will be merged with the default one:

application:
	scanDirs:
		- foo

In this case scanDirs will contain values %appDir% and foo. If we want to disable or overwrite this configuration option, we need to use ! modifier:

application:
	scanDirs!:
		- foo

Now scanDirs will contain only foo.

scanComposer

Default value: TRUE

This parameter specifies if Nette should look for presenters in the Composer classmap.

scanFilter

Default value: Presenter

Specifies the string which must be included in the file and class name.

Routing

routing:
	debugger: true  # debugger bar panel
	routes:
			index.php: Dashboard:default
			'<presenter>/<action>[/<id>]': Dashboard:default

Routes are in mask: action format.

Security

security:
	debugger: true  # debugger bar panel

	users:
		johndoe: secretpassword

	roles:
		guest:
		member:
		admin: [member]  # admin extends member

	resources:
		file:

By filling in users option you create SimpleAuthenticator, by defining roles or resources you create Nette\Security\Permission authorizator. More in User Authorization and Privileges.

HTTP headers

http:
	frames: ... # ovlivňuje hlavičku X-Frame-Options

For security reasons Nette Framework sends HTTP header X-Frame-Options: SAMEORIGIN by default, so that the page can be embedded in iframe only from pages on the same domain. This behavior may be unwanted in certain situations (for example if you are developing a facebook application). You can override this setting by frames: yes, frames: http://allowed-host.com or frames: no.

Mailing

Default mailer is SendmailMailer. By setting smtp you activate SmtpMailer.

mail:
	smtp: true  # use SmtpMailer instead of SendmailMailer
	# optional settings
	host: ...
	port: ...
	username: ...
	password: ...
	secure: # possible values are ssl, tls or null
	timeout: ...

Database

You can define multiple database connections, if you do so you can set which one will be automatically injected to your services by the autowired option. The following code shows how to set up one connection called default.

database:
	default:
		dsn: "sqlite2:%appDir%/models/demo.db"
		user: ...
		password: ...
		options: [PDO::MYSQL_ATTR_COMPRESS = true]
		debugger: false  # debugger bar panel
		explain: false   # explain queries in debugger bar
		reflection: discovered  # or static or classname, default is discovered
		autowired: true

This creates service @nette.database.default and sets reflection and cache for you.

Forms

You can change default validation error messages.

forms:
	messages:
		EQUAL: 'Please enter %s.'
		FILLED: 'Please complete mandatory field.'
		MIN_LENGTH: 'Please enter a value of at least %d characters.'
		EMAIL: '%label must be valid e-mail'

Latte

You can turn on and off XHTML rendering mode and register custom macros.

latte:
	xhtml: yes  # default is no
	macros:
		- App\MyLatteMacros::register  # static method, classname or callable

DI container

di:
	debugger: true  #debugger bar panel
	accessors: true  #enables $container->serviceName shortcut

Tracy debugger

tracy:
	email: webmaster@example.com  # for sending error logs
	strictMode: TRUE
	editor: ...
	browser: ...

	bar:  # debugger bar panels
		- Nette\Bridges\DITracy\ContainerPanel  # alias of DI container bar
		- IncludePanel
		- XDebugHelper('myIdeKey')
		- MyPanel(@MyService)

	blueScreen:  # blue screen panels
		- DoctrinePanel::renderException

Low-level modifications

All these settings affect final DI container. Compared to direct definition in services section it provides shorter and more straightaway syntax. If you need to tune these services by yourself, you can redefine them:

services:
	mail.mailer:
		factory: MySmtpMailer

	application.presenterFactory:
		factory: MyPresenterFactory

Or create new services extending the default ones:

services:
	myConnection < nette.database.default:
		setup:
			$onQuery: [ @logger::log ]

Services definitions

See services.

services:
	database: Nette\Database\Connection(%dsn%, %user%, %password%)

# or multi-lines
	database:
		factory: Nette\Database\Connection(%dsn%, %user%, %password%)

# or more multi-lines :-)
	database:
		class: Nette\Database\Connection
		arguments: [%dsn%, %user%, %password%]