Where do I put my code?

This is kind of a basic question, but I haven’t really seen a solid answer recommendation yet. As I’ve been developing with Yii, code related to controllers, views, data, etc… has a place. Post logic, goes into to the controller, menus get setup in views. Data conditions, scopes, behaviors, go into the model.

Fast forward a little…I wrote some code to resize images. I put it all into the actionIndex under a new controller. What I would have liked to do is put the code into a class, then build out some more robust functionality.

Where would I put this new class I want to create? Is it a "component"? Right now, everything in my components folder is an override of a base Yii class…so I tend to think, not there.

Do I create an Image Manipulation "widget"? Or are widgets more suited for use in customizing views?

Do I create an extension, even though I have no intent of packaging for distribution/re-installation?

It feels wrong to just leave linear code in the controller, when it should be built into a class.

Does anyone have any recommendations on when/how/why you would create your own custom classes and WHERE you would put them?

Thanks,

Matt

When I do create components that have project-wide functionality and it can be even used in other projects, I do include them into a ‘common’ or ‘lib’ folder that is after structured into behaviors/extensions/validators/etc.

I do create widgets when they render in views (tables, layers, inputs, etc)

I do create application components when they are used a lot throughout the application so it is easier to access

I do create extensions when they extend from common used components of Yii library

I do create components when I want to take advantage of CComponent functionality (events, etc)

I do create regular classes when their functionality is very specific and do not extend nor I want any feature provided by CComponent

Edit: there are more such as behaviors, validators, filters, and so on… but those are very specific in functionality so you should know when to develop them as such.

I hope it helped you

Cheers

This seems like the situation that I’m in. Where would you store a class file like this?

I also do have a "common" folder setup, right now its mostly for shared models.

Thanks,

Matt

common/utils for example

;)