This bundle is a solution to manage a media library, with back end system, and twig function for the front display., (*1)
How it works
This bundle VichUploaderBundle to work., (*2)
The back end system use bootstrap 4 to display all templates., (*3)
The MediaBundle provide some entities, controllers, forms and twig extension., (*4)
To read more about the using of this bundle, we invite you to check the docs., (*5)
Installation
-
Install it using composer, (*6)
$ composer require seraph/media-bundle
-
Add SeraphMediaBundle configuration, (*7)
# app/config/packages/seraph_media.yaml
seraph_media:
user_class: App\Entity\User
group_class: App\Entity\Group
# upload_folder: /uploads/
-
Add routing of the bundle, (*8)
# app/config/routes.yaml
seraph_media:
resource: '@SeraphMediaBundle/Controller'
type: annotation
# prefix: '/admin'
-
Update your database with User, Group and UploadedFile, (*9)
$ php bin/console doctrine:schema:update --force
Using
In this example I use FosUserBundle but you can use another bundle or your own classes., (*10)
-
Implement UserInterface, (*11)
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Seraph\Bundle\MediaBundle\Model\UserInterface;
/**
* @ORM\Entity
* @ORM\Table(name="user")
*/
class User extends BaseUser implements UserInterface
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $firstname;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $name;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Group")
* @ORM\JoinTable(name="user_group_user",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="group_user_id", referencedColumnName="id")}
* )
*/
protected $groups;
/**
* @ORM\OneToMany(targetEntity="Seraph\Bundle\MediaBundle\Entity\UploadedFile", mappedBy="user")
*/
protected $files;
// ...
}
-
Implement GroupInterface, (*12)
use FOS\UserBundle\Model\Group as BaseGroup;
use Doctrine\ORM\Mapping as ORM;
use Seraph\Bundle\MediaBundle\Model\GroupInterface;
/**
* @ORM\Entity
* @ORM\Table(name="group_user")
*/
class Group extends BaseGroup implements GroupInterface
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="Seraph\Bundle\MediaBundle\Entity\UploadedFile", mappedBy="group")
*/
protected $files;
// ...
}
Documentation
You can find in this folder, how you can use the bundle :, (*13)