SonataMediaBundle很多很多额外的字段都没有用

时间:2015-05-20 14:16:07

标签: sonata-admin sonata-media-bundle

有没有办法使用奏鸣曲媒体包轻松处理实体?   我尝试了所有解决方案,但没有任何工作......   很多问题 :    - 无法从集合中删除图像    - 每次无法添加多个文件    - 无法看到缩略图

这个捆绑包不容易使用,我想我会重写另一个捆绑包,我不会再花费更多的时间。

我认为我做的是好事:

<?php

namespace Immo\FichierBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Immeuble
*
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Immo\FichierBundle\Entity\ImmeubleRepository")
 */
class Immeuble
{
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var integer
 *
 * @ORM\Column(name="numero", type="integer")
 */
private $numero;

/**
 * @var Immo\EtablissementBundle\Entity\Etablissement
 *
 * @ORM\OneToOne(targetEntity="Immo\EtablissementBundle\Entity\Etablissement", cascade={"persist"})
 */
private $agence;

/**
 * @var Immo\FichierBundle\Entity\Adresse
 *
 * @ORM\OneToOne(targetEntity="Immo\FichierBundle\Entity\Adresse", cascade={"persist"})
 */
private $adresse;

/**
 * @var string
 *
 * @ORM\Column(name="vente", type="string", length=255)
 */
private $vente;

/**
 * @var string
 *
 * @ORM\Column(name="coproindiv", type="string", length=255)
 */
private $coproindiv;

/**
 * @var string
 *
 * @ORM\Column(name="exregulier", type="string", length=255)
 */
private $exregulier;


/**
 * @var string
 *
 * @ORM\OneToMany(targetEntity="Immo\FichierBundle\Entity\ImmeubleHasPhoto", mappedBy="immeuble",cascade={"all"}) 
 * @ORM\OrderBy({"ordre"="ASC"})
 */
private $photos;

/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}

public function __toString() {
    return $this->getNumero().' '.$this->getAdresse();
}

/**
 * Constructor
 */
public function __construct()
{
    $this->photo = new \Doctrine\Common\Collections\ArrayCollection();
}

/**
 * Set numero
 *
 * @param integer $numero
 * @return Immeuble
 */
public function setNumero($numero)
{
    $this->numero = $numero;

    return $this;
}

/**
 * Get numero
 *
 * @return integer 
 */
public function getNumero()
{
    return $this->numero;
}

/**
 * Set agence
 *
 * @param Immo\EtablissementBundle\Entity\Etablissement $agence
 * @return Immeuble
 */
public function setAgence(\Immo\EtablissementBundle\Entity\Etablissement $agence)
{
    $this->agence = $agence;

    return $this;
}

/**
 * Get agence
 *
 * @return Immo\EtablissementBundle\Entity\Etablissement 
 */
public function getAgence()
{
    return $this->agence;
}

/**
 * Set adresse
 *
 * @param Immo\FichierBundle\Entity\Adresse $adresse
 * @return Immeuble
 */
public function setAdresse(\Immo\FichierBundle\Entity\Adresse $adresse)
{
    $this->adresse = $adresse;

    return $this;
}

/**
 * Get adresse
 *
 * @return Immo\FichierBundle\Entity\Adresse 
 */
public function getAdresse()
{
    return $this->adresse;
}

/**
 * Set vente
 *
 * @param string $vente
 * @return Immeuble
 */
public function setVente($vente)
{
    $this->vente = $vente;

    return $this;
}

/**
 * Get vente
 *
 * @return string 
 */
public function getVente()
{
    return $this->vente;
}

/**
 * Set coproindiv
 *
 * @param string $coproindiv
 * @return Immeuble
 */
public function setCoproindiv($coproindiv)
{
    $this->coproindiv = $coproindiv;

    return $this;
}

/**
 * Get coproindiv
 *
 * @return string 
 */
public function getCoproindiv()
{
    return $this->coproindiv;
}

/**
 * Set exregulier
 *
 * @param string $exregulier
 * @return Immeuble
 */
public function setExregulier($exregulier)
{
    $this->exregulier = $exregulier;

    return $this;
}

/**
 * Get exregulier
 *
 * @return string 
 */
public function getExregulier()
{
    return $this->exregulier;
}

/**
 * Addphoto
 *
 * @param \Immo\FichierBundle\Entity\ImmeubleHasPhoto $photo
 * @return Personne
 */
public function addPhotos(\Immo\FichierBundle\Entity\ImmeubleHasPhoto $photo)
{
    $photo->setImmeuble($this);
    $this->photos[] = $photo;

    return $this;
}

/**
 * Remove removePhoto
 *
 * @param \Immo\FichierBundle\Entity\ImmeubleHasPhoto $photo
 */
public function removePhotos(\Immo\FichierBundle\Entity\ImmeubleHasPhoto $photo)
{
    $this->photos->removeElement($photo);
}

/**
 * {@inheritdoc}
 */
public function setPhotos($photos)
{
    $this->photos = new ArrayCollection();

    foreach ($photos as $photo) {
        $this->addPhoto($photo);
    }
}

/**
 * Get photo
 *
 * @return \Doctrine\Common\Collections\Collection 
 */
public function getPhotos()
{
    return $this->photos;
}
}

管理员类:

/**
 * @param FormMapper $formMapper
 */
protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->tab('Général')
            ->with('Général')
                ->add('numero')
                ->add('agence')
                ->add('adresse','sonata_type_model_list')
                ->add('vente')
                ->add('coproindiv')
                ->add('exregulier')
            ->end()
        ->end()
        ->tab('Photos')
            ->with('Liste photos')
                ->add('photos', 'sonata_type_collection', array(
                        'label' => false,
                        'type_options' => array('delete' => true),
                        'cascade_validation' => true,
                        'btn_add' => 'Ajouter une photo',
                        "required" => false
                    ), array(
                        'edit'              => 'inline',
                        'inline'            => 'table',
                        'sortable'          => 'ordre'
                    )
                )
            ->end()
        ->end()
    ;
}

加入实体:

<?php

namespace Immo\FichierBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* ImmeubleHasPhoto
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Immo\FichierBundle\Entity\ImmeubleHasPhotoRepository")
*/
class ImmeubleHasPhoto
{
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string
 *
 * @ORM\Column(name="nom", type="string", length=255,nullable=true)
 */
private $nom;

/**
 * @var integer
 * @ORM\Column(name="ordre", type="integer")
 */
private $ordre;

/** 
 * @ORM\ManyToOne(targetEntity="Immeuble", inversedBy="photos",cascade={"all"},fetch="LAZY") 
 * @ORM\JoinColumn(name="immeuble_id", referencedColumnName="id", nullable=false) 
 */
private $immeuble;

 /**
 * @var \Application\Sonata\MediaBundle\Entity\Media
 * @ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media",cascade={"all"},fetch="LAZY")
 * @ORM\JoinColumn(name="photo_id", referencedColumnName="id", nullable=false) 
 */
private $photo;


public function __construct() {

}

public function __toString() {
    return $this->getNom();
}

/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}

public function setImmeuble(\Immo\FichierBundle\Entity\Immeuble $immeuble)
{
    $this->immeuble = $immeuble;

    return $this;
}

/**
 * Get Immeuble
 *
 * @return \Immo\FichierBundle\Entity\Immeuble 
 */
public function getImmeuble()
{
    return $this->immeuble;
}

/**
 * Set photo
 *
 * @param string $photo
 * @return Application\Sonata\MediaBundle\Entity\Media
 */
public function setPhoto(\Application\Sonata\MediaBundle\Entity\Media $photo=null)
{
    $this->photo = $photo;

    return $this;
}

/**
 * Get photo
 *
 * @return Application\Sonata\MediaBundle\Entity\Media 
 */
public function getPhoto()
{
    return $this->photo;
}

/**
 * Set nom
 *
 * @param string $nom
 * @return ImmeubleHasPhoto
 */
public function setNom($nom)
{
    $this->nom = $nom;

    return $this;
}

/**
 * Get nom
 *
 * @return string 
 */
public function getNom()
{
    return $this->nom;
}

/**
 * Set ordre
 *
 * @param integer $ordre
 * @return ImmeubleHasPhoto
 */
public function setOrdre($ordre)
{
    $this->ordre = $ordre;

    return $this;
}

/**
 * Get ordre
 *
 * @return integer 
 */
public function getOrdre()
{
    return $this->ordre;
}
}

最后是我的连接实体的管理类:

/**
 * @param FormMapper $formMapper
 */
protected function configureFormFields(FormMapper $formMapper)
{
    $link_parameters = array();

    if ($this->hasParentFieldDescription()) {
        $link_parameters = $this->getParentFieldDescription()->getOption('link_parameters', array());
    }

    if ($this->hasRequest()) {
        $context = $this->getRequest()->get('context', null);

        if (null !== $context) {
            $link_parameters['context'] = $context;
        }
    }
    $formMapper
        ->add('nom',null,array('label'=>'Titre'))
        ->add('photo','sonata_type_model_list', array('required' => false), array(
        'link_parameters' => array('context' => 'Photos_immeuble')
        ))
        ->add('ordre','integer')
    ;
}

有什么问题吗?我已经过了很多天才能找到为什么我无法附上图像,但我什么都没发现......我真的认为这个包不是函数....

感谢您的帮助。

0 个答案:

没有答案