YII Framework - components question

Hello everyone,

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 would greatly appreciate any help with this.

Thank you!

Hey RedBishop,

Good to see you around, how you doing?

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.

Hi fretburner,

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)

Thanks!

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).

Great, thank you for clearing that up. :smiley:

Hope you enjoy the rest of the week. See you around.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.