When to use components and when to use extensions in Yii?
Asked Answered
C

1

23

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

Please clarify.

Caducous answered 8/12, 2011 at 4:29 Comment(0)
I
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.

Insolvency answered 8/12, 2011 at 9:32 Comment(4)
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?Britannic
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.Insolvency
Is it good to have a Component dependant on a model? That's my doubt.Thermostatics
@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.Insolvency

© 2022 - 2024 — McMap. All rights reserved.