PHP code example of idci / simple-media-bundle

1. Go to this page and download the library: Download idci/simple-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/ */

    

idci / simple-media-bundle example snippets



// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new IDCI\Bundle\SimpleMediaBundle\IDCISimpleMediaBundle(),
    );
}


...
use IDCI\Bundle\SimpleMediaBundle\Entity\MediaAssociableInterface;

/**
 * Object
 */
class MyObject implements MediaAssociableInterface
{
    ...

// This classic form creation
// $form = $this->createForm(new MyObjectType(), $myObject);

// Now work like this:
$form = $this->get('idci_simplemedia.manager')->createForm(
    new MyObjectType(),
    $myObject,
    array('provider' => 'file')
);

if ($this->getRequest()->isMethod('POST')) {
    $form->bind($this->getRequest());
    if ($form->isValid()) {
        $myObject = $this->get('idci_simplemedia.manager')->processForm($form);

        return $this->redirect($this->generateUrl(...));
    }
}

// Related to an object
$medias = $this->get('idci_simplemedia.manager')->getMedias($obj);

// Related to an object filter on tags
$medias = $this->get('idci_simplemedia.manager')->getMedias($obj, array('tag1', 'tag2'));

// Related to tags
$medias = $this->get('idci_simplemedia.manager')->getMedias(null, array('tag1', 'tag2'));

$this->get('idci_simplemedia.manager')->removeAssociatedMedias($obj);
$this->getDoctrine()->getManager()->flush();

$this->get('idci_simplemedia.manager')->removeMedia($media);
$em->flush();

// All tags
$tags = $this->get('idci_simplemedia.manager')->getTags();

// Related to an object
$tags = $this->get('idci_simplemedia.manager')->getTags($obj);
sh
php composer update