Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony][SF] Multiupload plików
damianooo
post
Post #1





Grupa: Zarejestrowani
Postów: 496
Pomógł: 2
Dołączył: 15.07.2011
Skąd: Katowice

Ostrzeżenie: (0%)
-----


Próbuję załadować kilka plików na raz w formularzu.
Niestety mam błąd:

  1. Expected argument of type "App\Entity\Image", "instance of Symfony\Component\HttpFoundation\File\UploadedFile" given at property path "files".

Nie wiem co mam źle.

Błąd wskazuje na kontroler na metodę handleRequest:
Form->handleRequest(object(Request)) in C:\xampp\htdocs\biuro\src\Controller\OfferController.php (line 29)

Tak wyglądają moje klasy:

  1. class OfferType extends AbstractType
  2. {
  3. public function buildForm(FormBuilderInterface $builder, array $options)
  4. {
  5. $builder
  6. ->add('name', TextType::class)
  7. ->add('description', TextareaType::class)
  8. ->add('files',FileType::class, [
  9. 'multiple' => true
  10. ]
  11. )



  1. class OfferController extends AbstractController
  2. {
  3. public function createOffer(Request $request) {
  4.  
  5. $offer = new Offer();
  6. $form = $this->createForm(OfferType::class, $offer);
  7. $form->handleRequest($request);


  1. class Offer
  2. {
  3. /**
  4.   * @ORM\OneToMany(targetEntity="Image", mappedBy="offer", cascade={"persist"})
  5.   */
  6. private $files;



  1. <tr>
  2. <th>Nazwa:</th>
  3. <td>{{ form_widget(form.name) }}</td>
  4. </tr>
  5. <tr>
  6. <th>Opis:</th>
  7. <td>{{ form_widget(form.description) }}</td>
  8. </tr>
  9. <tr>
  10. <th>Zdjęcia:</th>
  11. <td>{{ form_widget(form.files) }}</td>
  12. </tr>
  13. <tr>
  14. <th></th>
  15. <td>{{ form_widget(form.save) }}</td>
  16. </tr>
  17. </tbody>


Ten post edytował damianooo 23.03.2021, 21:40:22
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 25.09.2025 - 19:57