• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to access controller property inside a filter?

#1
Hello, 

Is possible to access a controller property like $this->checkUser inside a before Filter?

I need to perform some additional actions depending on the called controller's property value set on __contruct() method.


Regards.
Reply

#2
The controller is not available from the filters, just the Request and Response objects.
Reply

#3
(04-16-2020, 10:59 AM)kilishan Wrote: The controller is not available from the filters, just the Request and Response objects.

Thanks for the reply.  Do you have another idea about how to check user credentials (not only if is logged in) according to specific controller called?

Regards.
Reply

#4
I've done something that sounds vaguely similar to what you're wanting to do (this one keeps a log (using another model 'controller') to flag users who are possibly up to no good) using the CI Throttle filter:

Code:
class Throttle implements FilterInterface
{
        public function before(RequestInterface $request)
        {
                $throttler = Services::throttler();

                // Restrict an IP address to no more than set requests per MINUTE across the site
                if ($throttler->check($request->getIPAddress(), THROTTLER_REQUESTS_PER_MIN_LIMIT, MINUTE) === FALSE) {

                        $userAuditModel = new \App\Models\UserAuditModel();
                        $userAuditModel->audit_throttle_count_increment();    // keep a record of this user's throttling

            return Services::response()->setStatusCode(429);    // will result in a Server Time-Out Error modal being shown
                }
        }
...

... not sure if this helps?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.