Answer the question
In order to leave comments, you need to log in
Is this approach normal in organizing data models?
Is this approach acceptable in the organization of data model classes (see code example) or is it the wrong way? It is more convenient for me when the classes accompanying the main data model are located in the same file and access to them is provided precisely through the main class, but is this use case acceptable or categorically not, and what problems can this cause?
User model, User.php file
class User extends ActiveRecord
{
public static function getUserLinksObj()
{
return new UserLinks();
}
}
class UserLinks extends ActiveRecord
{
public static function findLinks($userId)
{
return static::find()->where(['user_id' => $userId])->all();
}
}
$userLinks = User::getUserLinksObj()->findLinks($userId);
// дальнейшая обработка
Answer the question
In order to leave comments, you need to log in
Basically, you have two questions:
Namespaces and classes MUST follow an "autoloading" PSR: [PSR-0, PSR-4].PSR-1
This means each class is in a file by itself, and is in a namespace of at least one level: a top-level vendor name.
It seems to me that here the author needs to know whether the approach of obtaining data through another class is correct,
and how to store the class in this file or in another matter of taste.
Aggregate Root .
If a UserLinks object cannot exist without a User object, then User acts as the parent element in the node through which child elements are retrieved.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question