Symfony 2 Загрузить файл с помощью пакета craue

Я использую сверток для моей формы, и мне нужна помощь для загрузки фото:
У меня 2 сущности, плоские и плоские.
Проблема в том, что на мой взгляд ничего не появляется! без ошибок, просто ничего ..
Спасибо за помощь ребята

Моя квартира сущности содержит мои сущности:

class Flat
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Expose()
* @Type("integer")
* @Groups("flat_public")
*/
private $id;

/**
* @var \Doctrine\Common\Collections\ArrayCollection $flatpics
*
* @ORM\OneToMany(targetEntity="***\FrontBundle\Entity\Flatpics", mappedBy="flat", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\JoinColumn(name="flatpics", referencedColumnName="id", onDelete="CASCADE")
* @Expose()
* @Type("ArrayCollection<***\FrontBundle\Entity\Flatpics>")
* @Groups("flat_public")
*/
private $flatpics;

/**
* @var \Doctrine\Common\Collections\ArrayCollection $room
*
* @ORM\OneToMany(targetEntity="***\FrontBundle\Entity\Room", mappedBy="flat", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\JoinColumn(name="room", referencedColumnName="id", onDelete="CASCADE")
* @Expose()
* @Type("ArrayCollection<***\FrontBundle\Entity\Room>")
* @Groups("flat_public")
*/
private $rooms;

/**
* @var User
*
* @ORM\ManyToOne(targetEntity="Application\Sonata\UserBundle\Entity\User", inversedBy="flats", cascade={"persist"})
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")
* @Expose()
* @Type("Application\Sonata\UserBundle\Entity\User")
* @Groups("flat_public")
*/
private $user;
etc...

Моя сущность смущается:

class Flatpics
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @var string
*
* @ORM\Column(name="path", type="string", length=255, nullable=true)
* @Expose()
* @Type("string")
* @Groups("flat_public")
*/
private $path;

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

/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime", nullable=true)
*/
protected $createdAt;

/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
protected $updatedAt;

/**
* @var UploadedFile
* @Assert\File(
*     maxSize = "50000k",
*     mimeTypes = {"image/png", "image/jpg", "image/jpeg", "image/gif"},
* )
*/
private $file;

/**
* @var ***\FrontBundle\Entity\Flat
*
* @ORM\ManyToOne(targetEntity="***\FrontBundle\Entity\Flat", inversedBy="flatpics")
* @ORM\JoinColumn(name="flat_id", referencedColumnName="id")
*/
private $flat;
etc...

FormType Загрузить:

class UploadForm extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
switch ($options['flow_step']) {
case 1:
$builder
->add('flatpics', 'collection', array('type' => new FlatpicsType(),'allow_add' => true,
'by_reference' => false,
'allow_delete' => true,
'prototype' => true, 'label' => 'Images'
));
break;
}
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => '***\FrontBundle\Entity\Flat',
));
}

public function getName()
{
return '***_frontbundle_flat_upload';
}
}

FormType Flatpics:

class FlatpicsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('file', 'file', array(
'constraints' => array(
new Assert\File(array(
'maxSize' => '50000k',
'mimeTypes' => array(
'image/png',
'image/jpeg',
'image/gif'
),
))
),
'required' => false
))
;
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => '***\FrontBundle\Entity\Flatpics'
));
}

public function getName()
{
return '***_frontbundle_flatpics';
}
}

FlatController:

class FlatController extends Controller
{

/**
* @Route("/flat/flatupload/", name="_FormFlow_Upload")
* @Template
*/
public function flatUploadAction()
{
return $this->processFlow(new Flat(), $this->getUploadPicsFlow(true));
}

protected function getUploadPicsFlow($dynamicStepNavigationEnabled) {
$flow = $this->get('***.form.flow.upload');
$flow->setAllowDynamicStepNavigation($dynamicStepNavigationEnabled);
// separate data per mode
if ($dynamicStepNavigationEnabled) {
$flow->setStepDataKey($flow->getStepDataKey() . '_dsn');
}
return $flow;
}protected function processFlow($formData, FormFlowInterface $flow)
{
$flow->bind($formData);
$form = $flow->createForm();
if ($flow->isValid($form)) {
$flow->saveCurrentStepData($form);
if ($flow->nextStep()) {
// create form for next step
$form = $flow->createForm();
} else {
// flow finished
// ...
$flow->reset();
$em = $this->getDoctrine()->getEntityManager();
$em->persist($formData);
$em->flush();
return $this->redirectToRoute('***_front_flat_flatupload', array(), 301);
}
}
return array(
'form' => $form->createView(),
'flow' => $flow,
'formData' => $formData,
);
}}

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]