What are the intended uses of startup() and checkRequirements()?

netteman
Member | 122
+
0
-

Hi all,

I'd like to check whether a user is logged in the BasePresenter of my AdminModule (so I don't have to do it manually in every single presenter)

I used the startup() method and it works but I also found the checkRequirements() method and I don't what are their intended uses as they are mentioned quite briefly https://doc.nette.org/…thentication)

public function startup()
{
    parent::startup();
    if (!$this->user->isLoggedIn()) {
        $this->redirect(":Adminauth:Sign:in");
    }

}

Last edited by netteman (2017-05-04 20:53)

esorimer
Member | 114
+
0
-

Hi,
checkRequirements() is called juste before startup().
It is used to check anotations, which you can use to set privilieges,
see annotations

You are not using anotations i guess, so using startup() is fine. (and i do not think people use checkRequirements() often, as it is poorly documented)

David Matějka
Moderator | 6445
+
0
-

also, it is called before every action/render/handle method with proper method reflection, so you can check access to specific method of the presenter