PHP code example of braunstetter / media-bundle

1. Go to this page and download the library: Download braunstetter/media-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

braunstetter / media-bundle example snippets




namespace App\Entity;

use Braunstetter\MediaBundle\Entity\BaseFile;

class Image extends BaseFile
{

}


namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use App\Entity\Media\Image;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

#[ORM\Entity()]
class Page 
{

    #[ORM\ManyToMany(targetEntity: Image::class, cascade: ["ALL"], orphanRemoval: true)]
    private $image;

    public function __construct()
    {
        $this->image = new ArrayCollection();
    }

    public function getImage(): Collection
    {
        return $this->image;
    }
    
    public function addImage(Image $image): self
    {
        if (!$this->image->contains($image)) {
            $this->image[] = $image;
        }

        return $this;
    }

    public function removeImage(Image $image): self
    {
        $this->image->removeElement($image);

        return $this;
    }
}

$form->add('image', MediaCollectionType::class, [
    'entry_type' => ImageType::class,
    'entry_options' => [
        '

$uploader->setFolder('/image/redactor')
$uploader->upload($imageEntity)
 
$uploader->upload($imageEntity, false)