1. Go to this page and download the library: Download perfectneeds/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/ */
perfectneeds / media-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new \PN\ServiceBundle\PNServiceBundle(),
new \PN\MediaBundle\PNMediaBundle(),
// ...
);
}
// src/PN/Bundle/MediaBundle/Entity/Image.php
namespace PN\Bundle\MediaBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
// DON'T forget the following use statement!!!
use PN\MediaBundle\Entity\Image as BaseImage;
use PN\MediaBundle\Model\ImageInterface;
use PN\MediaBundle\Model\ImageTrait;
/**
* @ORM\HasLifecycleCallbacks
* @ORM\Table("image")
* @ORM\Entity(repositoryClass="PN\MediaBundle\Repository\ImageRepository")
*/
class Image extends BaseImage implements ImageInterface {
use ImageTrait;
/**
* @ORM\PreRemove
*/
public function preRemove() {
$this->removeUpload();
}
// *IMPORTANT* Add this code of you use PNContentBundle
/**
* @ORM\ManyToMany(targetEntity="\PN\Bundle\ContentBundle\Entity\Post", mappedBy="images")
*/
protected $posts;
/**
* Constructor
*/
public function __construct() {
parent::__construct();
$this->posts = new \Doctrine\Common\Collections\ArrayCollection();
// your own logic
}
// if not use the PNContentBundle use this constructor
public function __construct()
{
parent::__construct();
// your own logic
}
}
// src/PN/Bundle/MediaBundle/Entity/Document.php
namespace PN\Bundle\MediaBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
// DON'T forget the following use statement!!!
use PN\MediaBundle\Entity\Document as BaseDocument;
use PN\MediaBundle\Model\DocumentInterface;
use PN\MediaBundle\Model\DocumentTrait;
/**
* @ORM\HasLifecycleCallbacks
* @ORM\Table("document")
* @ORM\Entity(repositoryClass="PN\Bundle\MediaBundle\Repository\DocumentRepository")
*/
class Document extends BaseDocument implements DocumentInterface {
use DocumentTrait;
/**
* @ORM\PreRemove
*/
public function preRemove() {
$this->removeUpload();
}
// if not use the PNContentBundle use this constructor
public function __construct()
{
parent::__construct();
// your own logic
}
}
// src/PN/Bundle/MediaBundle/Repository/ImageRepository.php
namespace PN\Bundle\MediaBundle\Repository;
use PN\MediaBundle\Repository\ImageRepository as BaseImageRepository;
class ImageRepository extends BaseImageRepository {
}
// src/PN/Bundle/MediaBundle/Repository/DocumentRepository.php
namespace PN\Bundle\MediaBundle\Repository;
use PN\MediaBundle\Repository\DocumentRepository as BaseDocumentRepository;
class DocumentRepository extends BaseDocumentRepository {
}