Take this Ruby on Rails example.
class SomeController < ApplicationController
before_filter :generateRandomValue
def generateRandomValue
//generates a random value between 0 and 10
end
def getBoo
//Return value generated by the method above
end
end
If we call getBoo
, class will run generateRandomValue
first because it has a general scoped before filter.
We can also tweak this before filters in Ruby on Rails, like;
method x,y,z runs before a method.
method 1,2,3 runs before b,c,d method.
method always, always runs. (think it like PHP's __construct())
Is there any way to set before filters before controller method calls in Laravel 4?
The main reason is, I want to DRY most of my code by applying before filters.
Thank you.