Search code examples
yiiyii-componentsyii-extensions

When to use components and when to use extensions in Yii?


I'm a little bit confused about the purpose of components and extensions folders in protected/

Please clarify.


Solution

  • According to my little experience on Yii:

    Components are the classes which can help you write the business logic on the basis of your models. You definitely don't want to code all of your work in controllers, then you need the component to distribute your code and call it in controller.

    Extensions are like the libraries, which basically are not dependent on your models, and hence can be reused anywhere in current or later projects. For example: an email extension, or a class that send tweet to your twitter account.

    It may be different for other coders/users.