23

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

Please clarify.

bool.dev
  • 17,508
  • 5
  • 69
  • 93
oaziz
  • 1,362
  • 1
  • 17
  • 32

1 Answers1

25

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.

Arfeen
  • 2,553
  • 5
  • 29
  • 48
  • Arfeen, excellent explanation, I get extensions now. What about components though? Can you give an example of when something would go here instead of directly in the model class? – John Zumbrum Jun 11 '12 at 15:35
  • 3
    This is my common practice, suppose you have to manage users so I always create a component where the functions will manages users, for example login, logout, new user, status change and all the functions related to a user/users tasks. And definitely all these functions would be using user model. – Arfeen Jun 12 '12 at 05:02
  • Is it good to have a Component dependant on a model? That's my doubt. – JorgeeFG May 16 '13 at 14:49
  • @Jorge It depends purely on your design. You can have such component. You also have options to write methods in the desired model. Again it depends. – Arfeen May 16 '13 at 20:25