Download the PHP package perfectneeds/media-bundle without Composer
On this page you can find all versions of the php package perfectneeds/media-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download perfectneeds/media-bundle
More information about perfectneeds/media-bundle
Files in perfectneeds/media-bundle
Package media-bundle
Short Description Media Bundle Manage images and documents
License
Homepage https://perfectneeds.com
Informations about the package media-bundle
Getting Started With PNMediaBundle for manage uploading files like images or documents
Prerequisites
- Symfony 3.4
- PNServiceBundle
Installation
Installation is a quick (I promise!) 9 step process:
- Download PNMediaBundle using composer
- Enable the Bundle in AppKernel
- Create your Image class
- Create your Document class
- Create your ImageRepository class
- Create your DocumentRepository class
- Configure the PNMediaBundle
- Import PNMediaBundle routing
-
Update your database schema
Step 1: Download PNMediaBundle using composer
Require the bundle with composer:
Step 2: Enable the Bundle in AppKernel
Require the bundle with composer:
Step 3: Create your Image class
The goal of this bundle is to persist some Image
class to a database. Your first job, then, is to create the
Image
class for your application. This class can look and act however
you want: add any properties or methods you find useful. This is your
Image
class.
The bundle provides base classes which are already mapped for most fields to make it easier to create your entity. Here is how you use it:
- Extend the base
Image
class (from theEntity
folder if you are using any of the doctrine variants) - Map the
id
field. It must be protected as it is inherited from the parent class.
Caution!
When you extend from the mapped superclass provided by the bundle, don't redefine the mapping for the other fields as it is provided by the bundle.
In the following sections, you'll see examples of how your Image
class should look, depending on how you're storing your posts (Doctrine ORM).
Note
The doc uses a bundle named MediaBundle
. However, you can of course place your post class in the bundle you want.
Caution!
If you override the construct() method in your Image class, be sure to call parent::construct(), as the base Image class depends on this to initialize some fields.
Doctrine ORM Image class
If you're persisting your post via the Doctrine ORM, then your Image
class should live in the Entity namespace of your bundle and look like this to start:
*You can add all relations between other entities in this class
Step 4: Create your Document class
The goal of this bundle is to persist some Document
class to a database. Your first job, then, is to create the
Document
class for your application. This class can look and act however
you want: add any properties or methods you find useful. This is your
Document
class.
The bundle provides base classes which are already mapped for most fields to make it easier to create your entity. Here is how you use it:
- Extend the base
Document
class (from theEntity
folder if you are using any of the doctrine variants) - Map the
id
field. It must be protected as it is inherited from the parent class.
Caution!
When you extend from the mapped superclass provided by the bundle, don't redefine the mapping for the other fields as it is provided by the bundle.
In the following sections, you'll see examples of how your Document
class should look, depending on how you're storing your documents (Doctrine ORM).
Note
The doc uses a bundle named MediaBundle
. However, you can of course place your document class in the bundle you want.
Caution!
If you override the construct() method in your Document class, be sure to call parent::construct(), as the base Document class depends on this to initialize some fields.
Doctrine ORM Document class
If you're persisting your document via the Doctrine ORM, then your Document
class should live in the Entity namespace of your bundle and look like this to start:
*You can add all relations between other entities in this class
Step 5: Create your ImageRepository class
You can use this Repository
to add any custom methods
Step 6: Create your DocumentRepository class
You can use this Repository
to add any custom methods
Step 7: Configure the PNMediaBundle
Add the following configuration to your config.yml file according to which type of datastore you are using.
Step 8: Import PNMediaBundle routing files
Step 9: Update your database schema
Now that the bundle is configured, the last thing you need to do is update your database schema because you have added a new entity.
How to use PNMediaBundle
- How to upload image in Controller
-
How to upload document in Controller
1. How to upload image in Controller
- $entity : an instance of your entity that you would like to add this image to it this entity must be contains one of these methods addImage() or setImage()
- $file: must be an instance of FileUploader
- $type: the type of this entity to set the upload path this type must be found in
ImageSetting
or configured inapp/config.yml
- $request (optional) : an instance of Symfony\Component\HttpFoundation\Request
- $imageType (Defualt value : Main Image): and any image type
2. How to upload document in Controller
- $entity : an instance of your entity that you would like to add this document to it this entity must be contains one of these methods addDocument() or setDocument()
- $file: must be an instance of FileUploader
- $type: the type of this entity to set the upload path this type must be configured in
app/config.yml
- $request (optional) : an instance of Symfony\Component\HttpFoundation\Request
Reporting an issue or a feature request
Issues and feature requests are tracked in the Github issue tracker.
When reporting a bug, it may be a good idea to reproduce it in a basic project built using the Symfony Standard Edition to allow developers of the bundle to reproduce the issue by simply cloning it and following some steps.
All versions of media-bundle with dependencies
symfony/framework-bundle Version ~4.0|~5.0|~6.0
perfectneeds/service-bundle Version ~2.0
ext-gd Version *