XF 2.2 preDispatchController for public controllers

stromb0li

Well-known member
Is there an equivalent for non-admin controllers to do pre-action validations like in the admin panel?

I.e. I would like to run this in my public controller:

PHP:
protected function preDispatchController($action, ParameterBag $params)
    {
        $visitor = \XF::visitor();
        $auth = $visitor->Auth->getAuthenticationHandler();
        if (!$auth)
        {
            return $this->noPermission();
        }
    }
 
The preDispatchController method is called on all controllers (admin, public, API).
 
Hmm, you are right, it looks like it's executing, but the issue is actually that returing $this->noPermission(); doesn't seem to be honored.

Is there an equivalent on the public side?

PHP:
protected function preDispatchController($action, ParameterBag $params)
{
    return $this->noPermission();       
}
 
The return value isn't captured, you need to throw a response exception. It's the same in the admin controllers.

PHP:
protected function preDispatchController($action, ParameterBag $params)
{
    throw $this->exception($this->noPermission());
}
 
Me:
Summer Driving GIF


Appreciate the help as always!
 
Back
Top Bottom