Automatic installation of the variable in all templates
Notice: This thread is very old.
- bafoed
- Member | 6
How to load a variable in all the templates?
abstract class BasePresenter extends Nette\Application\UI\Presenter
{
public function __construct() {
$this->template->u = $this->session->getSection('user')->user;
}
}
Throws:
Call to a member function getByType() on a non-object.
File: ...\libs\Nette\Application\UI\Presenter.php Line: 1433
and
abstract class BasePresenter extends Nette\Application\UI\Presenter
{
public function __construct() {
parent::__construct();
$this->template->u = $this->session->getSection('user')->user;
}
}
Throws:
Argument 1 passed to Nette\Application\UI\Presenter::__construct() must implement interface Nette\DI\IContainer,
none given, called in \path\to\app\presenters\BasePresenter.php on line 13 and defined
- Vojtěch Dobeš
- Gold Partner | 1316
You forgot to call Move your code to
parent::__construct();
first. But
that's not the ideal solution.beforeRender()
method.
protected function beforeRender()
{
parent::beforeRender();
$this->template->u = $this->session->getSection('user')->user;
}
Presenters will be refactored in close future, but now it's better to avoid using presenter's constructor.
Last edited by vojtech.dobes (2012-03-25 18:49)