Doctrine\ORM\EntityManager::persist PHP Method

persist() public method

The entity will be entered into the database at or before transaction commit or as a result of the flush operation. NOTE: The persist operation always considers entities that are not yet known to this EntityManager as NEW. Do not pass detached entities to the persist operation.
public persist ( $entity )
    public function persist($entity)
    {
        if ( ! is_object($entity)) {
            throw new \InvalidArgumentException(gettype($entity));
        }
        $this->errorIfClosed();
        $this->unitOfWork->persist($entity);
    }

Usage Example

コード例 #1
1
ファイル: Attachment.php プロジェクト: riki343/naidusvoe
 /**
  * @param EntityManager $em
  * @param array $imagesArray
  * @param Advertisment $adv
  * @return array
  */
 public static function uploadImages(EntityManager $em, $imagesArray, $adv)
 {
     $dummyImage = '/resources/images/adv-default.png';
     $basePath = 'uploads/' . $adv->getId();
     $uploadedImages = array();
     $adv = $em->getRepository('NaidusvoeBundle:Advertisment')->find($adv->getId());
     $fs = new Filesystem();
     $counter = 1;
     if ($imagesArray) {
         foreach ($imagesArray as $image) {
             $image = (object) $image;
             if ($image->image !== null) {
                 $imagePath = $basePath . '/' . $counter . '.jpg';
                 $image = explode(',', $image->image);
                 $image = base64_decode($image[1]);
                 $fs->dumpFile($imagePath, $image);
                 $attachment = new Attachment();
                 $attachment->setAdvertisment($adv);
                 $attachment->setImage($imagePath);
                 $em->persist($attachment);
                 $uploadedImages[] = $attachment;
                 $counter++;
             }
         }
     }
     if ($counter === 1) {
         $attachment = new Attachment();
         $attachment->setAdvertisment($adv);
         $attachment->setImage($dummyImage);
         $em->persist($attachment);
         $uploadedImages[] = $attachment;
     }
     return $uploadedImages;
 }
All Usage Examples Of Doctrine\ORM\EntityManager::persist