Welcome Guest, Not a member yet? Register   Sign In
What is the best way to fill an object with data from a database
#1

Hi all

What is the best way to fill an array objects with data from a database

My code
PHP Code:
class ProductsContentComposite extends AbstractContentComposite {
 
   public function addElement(InterfacePrototype $element)
 
   {
 
       $this->elements[] = $element;
 
   }

In Controller
PHP Code:
$productsComposite = new ProductsContentComposite();
/* some logic */
$results $this->product_model->getAll();
$productPrototype = new ProductContentPrototype();
/* some logic */
foreach ($results as $result)
{
$clonePrototype = clone $productPrototype;
/* some logic */
$productsComposite->addElement($clonePrototype);

Is this the right way or not?
Reply


Messages In This Thread
What is the best way to fill an object with data from a database - by phpforever2017 - 05-28-2017, 12:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB