load data from database in @layout.latte from every presenter?

Notice: This thread is very old.
frocco
Member | 46
+
0
-

Hello,

On my main layout I have 4 footer sections that display info from a database.
How can I do this in nette?

I have several presenters and do not want to put the db code in all presenters.

<footer
{info1} {info2}
</footer>

Thank you

Blujacker
Member | 89
+
0
-

Hello,

I believe you have to create a new class BasePresenter from which all other presenters will inherit. In this BasePresenter you can pull any necessary data from model in method beforeRender and they will be available in all child presenters.

abstract class BasePresenter extends \Nette\Application\UI\Presenter{
	protected function beforeRender(){
		$this->template->info1 = xyz;
		$this->ŧemplate->info2 = xzy;
}

final class HomepagePresenter extends BasePresenter{
	/**
     * In case you need to call beforeRender method in inheriting presenter,
     * do not forget to call parent::beforeRender()
	 */
    protected function beforeRender(){
		parent::beforeRender();
	}
}
Oli
Member | 1215
+
0
-

And some model classes you can inject to your basePresenter this way

frocco
Member | 46
+
0
-

Thank you,

Getting error

protected function beforeRender()
    {
    	$this->template->service_footer = $this->database->table('pages')->where('url', '/services/')->limit(1);
    }

Call to a member function table() on a non-object

Last edited by frocco (2015-04-10 13:12)