Configuring Nette in Neon

I bet you didn’t know it but Nette’s internal behaviour can be configured quite extensively in config.neon. Default form error messages, switching on/off debugger panels, changing mailer to use SMTP instead of mail() and so on. All of this can be set up in PHP but keeping configuration out of your code helps making it easier to read. Do have a look, it has a great potential. As usually, the documentation is pretty bare and it’s up to us to discover the whole truth. This post contains some additional information that I scavenged in forums or discovered myself.

Assign user a session namespace (session is the default storage):

  1. services:
  2.   nette.userStorage:
  3.     setup:
  4.       – setNamespace("myName")

Install custom macros using a factory:

  1. factories:
  2.   nette.latte:
  3.     class:  NLatteFilter
  4.     setup:
  5.       – CustomMacros::install(::$service->getCompiler())

Use your own database debugger panel:

  1. services:
  2.   nette.database.defaultConnectionPanel: NotORM_DatabasePanel

Switch mailer to SMTP/localhost in order to catch all e-mails with MailSnag:

  1. development < common:
  2.   nette:
  3.     mailer:
  4.       smtp: true
  5.       host: localhost

Post a comment if you know more goodies.

Tags:

2 Responses to “Configuring Nette in Neon”

  1. Hi, just to be clear, I’ve removed that part with user namespace from doc, because it’s for configuration options, not for services “hacking”. If you’re interested, you may send a pullrequest (I will do it eventually, but not in near future), so we could write this

    nette:
        user:
            namespace: myName
    

    There is already syntax for macros, that is not yet in stable, so it’s not in documentation http://doc.nette.org/cs/configuring/nette-framework?rev=12#toc-sablony

  2. Thanks for the explanation and heads up on the macros syntax.
    To me, there’s no difference between “hacking” and proper configuration in Nette. It’s all magic, pieces of code that I see someone using in the forum. The line that you draw between “good” and “bad” is artificial, in my opinion. I bet that in a few months time you yourself will consider today’s good practices outdated and inappropriate.

Leave a Reply