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

25 days ago

netteman
Member | 50
+
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/…cess-control)

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

}

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

20 days ago

esorimer
Member | 106
+
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)

20 days ago

David Matějka
Moderator | 4832
+
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

Board footer

Hostováno na e-infrastruktuře CESNET. Děkujeme za podporu sdružení CESNET, z.s.p.o.