Functions File

Normally when I write a script I have write all my reusable functions in a functions.php file and locate it in assets/inc/functions.php…

My question is, does Yii use some other way of using reusable functions? A certain file, a certain location… Still pretty new to Yii and I want to make this current application as efficient as possible.

There is no special file or place where such a file with helper functions should be saved. Place it somewhere under the protected folder and import it and you are doing fine.

Read the Use shortcut functions wiki article for further informations on this topic.


I prefer one or more helper classes with static methods and locate it in protected/components.

The DateUtil class is reusable for me in other projects:

DateUtil::getFormatedOutput(…), …

The SiteUtil class is only used for the specific project:

SiteUtil::getMainMenu(), …