A
A
Alexey Ukolov2014-08-08 14:07:18
PHP
Alexey Ukolov, 2014-08-08 14:07:18

How to correctly initialize a class with a large number of fields?

There is an ORM (rather, QueryBuilder), which has a getByID method that returns an array with the fields of one table row from the database.
We need to turn this array into an object that has its own business logic.
Let's take users for example.
The user has about two dozen fields, some of them are required, some are not. In the constructor of the User class, you need to list all these fields and pass them during initialization? And if you need to select not all fields, but only a part?
Please tell me what to read on this topic. Perhaps there are some existing open source solutions to learn from?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Kubintsev, 2014-08-08
@alexey-m-ukolov

DataMapper or ActiveRecord
Look for an ORM

M
Mikhail Osher, 2014-08-08
@miraage

Use Active Record, Luke.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question