Yii where to put a custom global function?
yii
Solution
create a file a MyClass.php inside components
You can write the static functions inside like
public static function is_home_page() {
$app = Yii::app();
return $app->controller->route == $app->defaultController;
}
which can be accessed from any where like controller, Model or View as below
MyClass::is_home_page();
hope this will help you to write any number of functions globally and access them from anywhere
Problem
I created a `is_home_page()` function to detect if a user is on the homepage or not, but i'm not sure where i should put it so i can be used on all views and themes? ``` function is_home_page() { $app = Yii::app(); return $app->controller->route == $app->defaultController; } ```