Skip to content

ronan-gloo/FuelPHP-Action-Filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

FuelPHP action filters

Custom implemetation of rails filters for fuelPHP framework.

Filters

Filter’s name can be a embedded controller’s method or a class.

  • before: filter is called on controller_started event
  • after: filter is called on controller_finished
  • around: filter is called on both controller_started and controller_finished events

Filters configuration

  • only: run filter only on defined actions
  • except: skip filter on defined actions
  • on: run filter on defined http methods (get, post, put …etc) and 'ajax'
  1. Setup filters as class properties

Run ‘ajax_only’ method on get or post, except for action_index()

public $before_filter = array(
    'ajax_only' => array(
        'except'    => 'index',
        'on'        => array('get', 'post')
    )
);

public function ajax_only()
{
    if( ! Input::is_ajax())
    {
        throw new HttpNotFoundException;
    }
}
  1. Setup filters under filter() method

You can set filters by using Filter class

public function filter()
{
    Filter::register('after', 'updated')->only('add', 'edit', 'delete')->on('post');
}

public function updated()
{
    // do something here...
}
  1. Calling a class instead of embedded controller’s method

It’s possible to use a class as filter, and optionnaly specify a method.
The controller instance and event name are passed to the constructor, or the method if provided in filter name.

Controller:

public $around_filter = array('Bench::action')

class Bench:

class Bench {
    
    public static function action($controller, $event)
    {
        $msg = get_class($controller).' '.$event.' '.$controller->request->action;
        
        Profiler::mark_memory($controller, $msg);
    }
    
}

About

Custom implemetation of rails filters for fuelPHP framework.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages