PHP code example of loamok / subformsmadeeasy

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

    

loamok / subformsmadeeasy example snippets


    public function registerBundles() {
        $bundles = array(
            ...,
            new Loamok\SubformsMadeEasyBundle\LoamokSubformsMadeEasyBundle(),
        );



namespace Your\WonderfullBundle\Entity;

use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;


/**
 * Article
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="ArticleRepository")
 * @ORM\HasLifecycleCallbacks
 */
class Article {

    /**
     * @var integer ... */
    private $id;

    /**
     * @var Collection
     *
     * @ORM\ManyToMany(targetEntity="Media", inversedBy="articles", cascade={"persist"})
     */
    private $medias;



namespace Your\WonderfullBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class ArticleType extends AbstractType {

    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
                ->add(...)
                ->add('medias', 'collection', array(
                    'type' => new MediaType(),
                    'allow_add' => true,
                    'allow_delete' => true,
                    'by_reference' => false
                ))