What is the best place (and approach) to store in Yii application general functions, that are used across entire project?
I would call them all a helper functions, but I may be wrong.
So: what is the best way of keeping them and in what form should they be written – widget, behavior or just a pure PHP code closed in form of a simple class?
[size="2"]Currently I have one class, named CFR (stands for Common Function Repository), from which I call these functions for example like that: CFR::isMobileBrowser(). This class is stored directly under /protected/components.[/size]
[size="2"]But I would like to know, if this is acceptable in terms of professional coding, or if there would be a better approach.[/size]
Written by the Yii inventory himself. What Qiang seems to suggest here is that you create a php file and put all your functions in it just like in the wiki. As for locations he only suggests to place the file in the protected/ folder and NOT in components that you plan to release as reusable extensions! To me (but that’s just me) this looks like your own third party code so I would go for creating a folder under extensions/ and put your function(s) in that folder and then include it in your index.php file. But there is nothing wrong with placing it in components/ folder
Hope this helps (to at least trigger a discussion)
I prefer to try to generalize the features that I have created over time and put them in one or more specific classes, then to create a component or an extension, to reuse possibly also in other applications.
For example, for the manipulation of date (different database), I created a class DateHelper and within a number of static methods that I can call. In this way, the resulting code is clean and reusable, traceable and also documented (if you use tools like doxygen or other).
The general idea of ZHtml sound interesting, however my current CFR contains also functions not responsible for text formatting. So the idea of splitting and grouping helpers in /protected/components/helpers also does seems interesting.
What will this give me?
(Aaarrgh! "Action failed: You have reached your quota of positive votes for the day")