Yii and static functions

Does bad practice have many static functions? I am using the Yii framework, and I realized that I have many static functions in my model classes. I put all my functions that are related to users in UserModel (I do the same for other models), but in the end I have a lot of static functions. Just wondering how you guys handle this. Many of these functions are simply query building functions instead of lazy loading, because I need to increase database performance.

Examples of functions:

User::getUserFromCampaign(1)
User::getUsersNotInCamapaigns()
User::isAdmin()
+4
source share
3 answers

, static .

, , , dandy!

Laravel. Laravel , , , , laravel. - .

+1

MVC - , . Factory - . , Google Factory . : FooFactory - , Foo ( FooModel, ).

MVC Factory , UserFactoryClass.

  • User::getUserFromCampaign(1)for me, a little strange. I suppose 1is a campaign identifier? Then which user returns this? Or can a campaign have only one user? If so, it UserFactory::getUserFromCampaign()will return a UserModel object for the user in the campaign with the given identifier.

  • User::getUsersNotInCampaign()I assume returns an array of UserModel objects? Refactor it in `UserFactory::getUsersNotInCampaign()and there you go.

  • User::isAdmin()should not be static at all. if ($user->isAdmin()) ..., notif(User::isAdmin($user))...

0
source

Source: https://habr.com/ru/post/1525475/


All Articles