Create a before filter method in php

Viewed 969

Just as a learning exercise I'm trying to build my own mini MVC in PHP.

What I want to achieve is a method that can be called before cetain other methods (similar to the before_filter method in ruby on rails)

For example; given the below controller class a user must have permission to do certain activities, so say I wanted to call checkPermissions() from BaseController before the create(), update() and delete().

class HomeController extends BaseController {

    beforeFilter(checkPermissions,['create','update','delete']);

    function index(){}

    function create(){}

    function update(){}

    function delete(){}

}

Can anyone give me any guidance on how to achieve this? or enlighten me on the PHP way of doing this sort of task. I'm relatively new to PHP so please be gentle.

2 Answers
Related