I have read a lot of topics about model mapping, but there have a lot of different ways to map the database, so I'm asking what is the best approach ?
In my case, I have created model and ORM, so my model use the ORM to work with the database, but for now the ORM support only database functionalities, I need to implement data mapping to my models but I'm not sure how to start with implementation and what technique to choose.
The final results I want to be something like this:
$user = new User()
$user->name = 'John Doe';
$user->title = 'Developer';
$user->save();
// or maybe
$newUser = $user::create(User $user);
$newUser->name;
Something like eloquent from laravel
So, I want the models to be represent the database fields, and to be "object of the database", not to be stdObjects or arrays...
My search tells me that I need to implement repository pattern, is it okay or ?
Also about the setters and getters... When I'm getting the database results, what is the best way to insert the results into the model properties ?
One of the way is to foreach the results from the database after querying and to set directly like $this->property = $dbResult->property
, but I mean that this is not the best way to do that...
So, if you have some hint or etc, please share with me Thanks
Aucun commentaire:
Enregistrer un commentaire