$this->getUser()->isAllowed() from within a Model?
- ShellyMurs
- Member | 2
hello I was just wondering if there is any way to grab the $user from within my model?
thank you
- nightfish
- Member | 517
ShellyMurs wrote:
hello I was just wondering if there is any way to grab the $user from within my model?
thank you
If Nette\Security\User
is a dependency of your model class, you
should pass it through the constructor.
class MyModel
{
/** @var \Nette\Security\User */
private $user;
public function __construct(\Nette\Security\User $user) {
$this->user = $user;
}
public function doSomething() {
if ($this->user->isAllowed()) {
// do stuff
}
}
}
Last edited by nightfish (2019-04-20 22:42)