Приветствую всех. Мне поручили модернизировать существующий сайт, который написан на Symfony 2. Сейчас имеется список новостей, к ним нужно добавить галерею. Я создала таблицу "news_gallery":
- id integer NOT NULL [pk]
- title character varying(255)
- image character varying(255) NOT NULL
- id_news integer [fk]
Создала класс NewsGallerys:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* Image
*
* @ORM\Table(name="news_gallery")
* @ORM\Entity(repositoryClass="AppBundle\Repository\NewsGallerysRepository")
* @Vich\Uploadable
*/
class NewsGallerys
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255, nullable=true)
*/
private $title;
/**
* @var string
*
* @ORM\Column(name="image", type="string", length=1024)
*/
private $image;
/**
* @Assert\File(
* maxSize="2m",
* mimeTypes={"image/png", "image/jpeg"}
* )
* @Vich\UploadableField(mapping="newsgallery", fileNameProperty="image")
* @var File
*/
private $imageFile;
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
}
public function getImageFile()
{
return $this->imageFile;
}
/**
* @ORM\ManyToOne(targetEntity="News", inversedBy="news_gallerys")
* @ORM\JoinColumn(name="id_news", referencedColumnName="id")
*/
public $news;
/**
* Set news
*
* @param \AppBundle\Entity\News $news
*
* @return news_gallerys
*/
public function setIdNews(\AppBundle\Entity\News $news)
{
$this->news = $news;
return $this;
}
/**
* Get news
*
* @return \AppBundle\Entity\News
*/
public function getIdNews()
{
return $this->news;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return Image
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set image
*
* @param string $image
* @return Image
*/
public function setImage($image)
{
$this->image = $image;
return $this;
}
/**
* Get image
*
* @return string
*/
public function getImage()
{
return $this->image;
}
}
В классе News добавила связь:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* News
*
* @ORM\Table(name="news")
* @ORM\Entity(repositoryClass="AppBundle\Repository\NewsRepository")
* @ORM\HasLifecycleCallbacks()
* @Vich\Uploadable
*/
class News
{
/**
* @ORM\OneToMany(targetEntity="NewsGallerys", mappedBy="news")
*/
private $news_gallerys;
/**
* Add news_gallerys
*
* @param \AppBundle\Entity\NewsGallerys $news_gallerys
*
* @return News
*/
public function addNewsGallery(\AppBundle\Entity\NewsGallerys $news_gallerys)
{
$this->news_gallerys[] = $news_gallerys;
return $this;
}
/**
* Remove news_gallerys
*
* @param \AppBundle\Entity\NewsGallerys $news_gallerys
*/
public function removeNewsGallery(\AppBundle\Entity\NewsGallerys $news_gallerys)
{
$this->news_gallerys->removeElement($news_gallerys);
}
/**
* Get news_gallerys
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getNewsGallery()
{
return $this->news_gallerys;
}
....
}
В публичную часть сайта в шаблон эту галерею вывела. А вот как сгенерировать это поле в форму добавления новостей через админку, понятия не имею. Перечитала кучу документации и кучу форумов, но ничего найти не могу.
Вот часть файла config.yml для Новостей и самой галереии:
News:
label: app.menu.news
class: AppBundle\Entity\News
list:
fields:
- name
- shortDescription
show:
fields:
- name
- shortDescription
- fullDescription
form:
fields:
- { property: 'created' }
- name
- shortDescription
- fullDescription
NewsGallerys:
label: app.menu.news_gallery
class: AppBundle\Entity\NewsGallerys
list:
fields:
- title
- { property: 'image', type: 'image', base_path: %app.path.newsgallery% }
show:
fields:
- title
- { property: 'image', type: 'image', base_path: %app.path.newsgallery% }
form:
fields:
- title
- { property: 'imageFile', type: 'vich_image' }
Как в News добавить свойство "news_gallerys" чтобы можно было загружать фото бесконечно много?
Благодарю за внимание.