I am a bit confused about the purpose of components in YII.
A YII application will most likely have a components folder containing one or more files. What components should I add to this folder? Must I always have a components folder? The sample YII application has a components folder containing Controller.php and UserIdentity.php. Is the Controller.php file always necessary?
I’ll start by saying that I’m not actually familiar with the Yii framework, but I was curious and had a look at the link. I think the idea is that components are the classes that you write when creating your Yii app. It seems that there is a base class, CComponent, that your components inherit from to get some basic functionality and access to the events system, which I’m guessing is an important part of the framework’s architecture.
A note of caution though - writing classes that extend from a framework class will tightly couple your code to that framework. It’ll make it impossible to take those classes and just drop them into a different project that doesn’t use Yii.
SitePoint did a series of articles on Yii Components a few years back, which you might find useful.
I’m OK thanks and you? Thank you for your help and the link to the articles. I’m still not 100% sure about components but hopefully will figure it out as I learn more about YII.
I’m sure you will know this. What purpose does the word “void” serve in a class definition?
For example:
public void collectLogs(CLogger $logger, boolean $processLogs=false)
It’s declaring the return type of the method. Void signifies that the method doesn’t return anything, but you could have int for an integer, or boolean for a true/false value, for example.
PHP doesn’t currently support return type hinting, but it’s sometimes used in documentation (as with the Yii docs).