How can I Autoload database?

Notice: This thread is very old.
Member | 12


I was wondering how can I autoload database in Nette?

I am coming from CodeIgniter and In CI, there is a file called autoload.php which I simply edit like this:

$autoload['libraries'] = array('database');

And after that, I don't have to load database in any controller anymore.

Is this (how) possible in Nette? Or do I have to write this in every presenter?

private $database;

public function __construct(Nette\Database\Context $database)
		$this->database = $database;
Member | 1215

If you don't want use model layer, you can inject to the BasePresenter this way: But you will find better way – use model layer. It's much more better wrap your queries into some methods…

Database must be set in config.neon (or another config file). For Example:…g.local.neon

That should be all.