basePresenter run code before other presenters are called

3 years ago

simonjcarr
Member | 28
+
0
-

I want to put some code in my basePresenter that runs at every page request, how do I do it?

3 years ago

CZechBoY
Member | 3360
+
0
-

Implement startup method with your custom code. Dont forget for calling parent::startup().

3 years ago

simonjcarr
Member | 28
+
0
-

@CZechBoY Thanks for the response. I have the following code in my BasePresenter.php file. But nothing happens. I would expect a white screen with just “I am here”.

Any idea what I might be doing wrong?

namespace App\Presenters;

use Nette;
use App\Model;

/**
 * Base presenter for all application presenters.
 */


abstract class BasePresenter extends Nette\Application\UI\Presenter {

    protected function startup() {
    parent::startup();
    echo "I am here";
    exit;
    }


}

3 years ago

Jan Endel
Member | 1024
+
+1
-

Hello @simonjcarr, do you extend your BasePresenter in your leaf Presenter?

Check especially the namespaces.

3 years ago

simonjcarr
Member | 28
+
0
-

@JanEndel Thanks. That was the issue, I was not extending BasePresenter

It works now.

Thanks