Answer the question
In order to leave comments, you need to log in
Which ORM to take for your project?
Haven't worked with ORM before but now I think the time has come. The idea is this: take ORM from any well-known framework, after all, they are available separately on the github, like, install it in your project and use it.
Here questions arose:
1) how do ORMs differ in different frameworks
2) which one is better to take, maybe not a framework at all, I understand that it’s a matter of taste, but here’s what your taste is and why
Answer the question
In order to leave comments, you need to log in
Let's take an ORM from two popular PHP frameworks. The first one will be Eloquent ("Native" for the Laravel framework) and the second one will be Doctrine (One of the available ORMs in the Symfony framework). The cardinal difference between these two "systems" is that the first one is developed on the basis of the Active Record pattern, and the second - using the Data mapper pattern. How are they different? I will give abstract code examples for the first and second patterns:
Active Record :
$user = new User(); // Создаем "сущность" нового пользователя.
$user->login = 'D3lph1'; // Устанавливаем его логин равным 'D3lph1'.
$user->password = '123456'; // Устанавливаем пароль этому пользователю.
$user->save(); // Сохраняем пользователя.
$user = new User();
$user->login = 'D3lph1'; // Устанавливаем его логин равным 'D3lph1'.
$user->password = '123456'; // Устанавливаем пароль этому пользователю.
$manager = ... // получаем объект менеджера (Например, из DI контейнера).
$manager->persist($user); // "Скармливаем" новоиспеченного пользователя нашему менеджеру.
// $manager->persis($user1); // Мы можем создать еще одного пользователя и уведомить менеджер об этом.
// $manager->persis($user2); // И еще одного...
$manager->flush(); // После выполнения этого метода данные отправятся в базу данных.
$result = $qb
->select(['id', 'login'])
->where('id', '<>', 3)
->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question