PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Vitalij Mik   Doctrine PHP ORM Example   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Doctrine PHP ORM Example
Examples of storing objects using Doctrine
Author: By
Last change:
Date: 2 years ago
Size: 798 bytes
 

Contents

Class file image Download
<?php

use BlackScorp\ORM\Entity\User;

$container = require_once __DIR__.'/depdency.php';

/** @var \Doctrine\ORM\EntityManager $entityManager */
$entityManager = $container[\Doctrine\ORM\EntityManagerInterface::class]();

/** @var \BlackScorp\ORM\Entity\User $user */
$user = $entityManager->find(User::class,1);
/** @var \BlackScorp\ORM\Entity\CartProducts $cartProduct */
foreach ($user->getCartProducts()->getIterator() as $cartProduct){
   
var_dump($cartProduct->getQuantity());
   
var_dump($cartProduct->getProduct()->getTitle());
   
var_dump($cartProduct->getProduct()->getPrice());

   
$cartProduct->setQuantity($cartProduct->getQuantity()+1);
   
$product = $cartProduct->getProduct();
   
$product->setPrice($_POST);
   
$entityManager->persist($product);
}

$entityManager->flush();