Importing components

Hi all,

I want to organiize my components a bit better than just putting everything in the "components" folder. It does not seem like I am allowed to however. So I am wondering if any of you guys have experienced the same. Heres my problem:

I have a group of classes, to extending from an abstract class, which i put in /components/Mail/. Then I put in the import statement in main.php application.components.. I have also tried application.components.Mail., and specified the path to every class directly.

This disables Yii of even creating the CWebapp object, "failed to open stream: No such file or directory (/home/ole/workspace/project/framework/YiiBase.php:396)". In the other case the class I am instantiating is not called.

I have checked that the php files have the exact same name as the class, which could be a problem.

Any help is much appreciated!


Ole M

Yes, you’re definitely allowed to order your libraries any way you want. Have a look at an example of my folder structure and config.

You’re on the right track with: application.components.Mail.* Are you on a *nix or Windows machine? Maybe you could post a screenshot or code from main.php.




I think you should create additional autoloader for all this stuff and register it

You can find an examples of how it is done with Zend Library :rolleyes:

Hi, and thanks for the responses, and sorry for the lateness of mine.

I’m on a unix machine, and everything regarding permissions is as it should be (i.e. no difference between folders working and not).

My autoloading looks like this:

// autoloading model and component classes









But when I use for ex. ‘application.utils.*’ I get the abovementioned problems.


You do not need to create additional autoloader, as previously suggested.

Check your paths and the path aliases you have set.

I have organized my components and there is no problem.

So, for example, I have my workflow component files in /components/workflow/. To load them, all I have to do is to import ‘application.components.workflow.*’

Can you please post your entire config file? Incorrect case could also cause issues.



Did you notice the lines at the top of the image?

Yii::setPathOfAlias('library', 'application.library');


You will also need these. In your example it would go something like this:

Yii::setPathOfAlias('utils', 'application.FOLDER_WHERE_YOUR_EXTENSIONS_ARE.utils');

I apologise if you already did this :)