Retrieving a Controller's Before and After Filters

Problem

You need to access the controller's filters.

Solution

Use getAfterFilters() or getBeforeFilters() in the controller.

class SomeController extends Controller {
    public function someMethod()
    {
        // Dump all the before filters
        var_dump($this->getBeforeFilters());
    }
}

Discussion

This is a lower level function.

Generally, you shouldn't need to access the filters within a controller method. The before filters already have ran successfully if you're in any method other than __construct().

The after filters won't fire until after the controller's method returns.

But if you need to access them, this recipe describes how.

comments powered by Disqus