Good to mention Annotations vs Attributes: Annotations style: /** * @ORM\Column(type="string", length=255) * @Assert\NotBlank * @Assert\Length(min=3) */ private $title; Attributes style: #[ORM\Column(type: 'string', length: 255)] #[Assert\NotBlank] #[Assert\Length(min: 3)] private $title;
@codewithdary2 жыл бұрын
Yes this is true, but it's something I've mentioned in one of the earlier videos. I'm trying to find a right balance in not repeating myself for certain stuff.
@ilyasbakirov2 жыл бұрын
@@codewithdary Yes of course you did! It's up to developer to choose the likely way. Annotations for me familiar from Java
@codewithdary2 жыл бұрын
Definitely! I agree with that one though, I had to get used to attribute style as well since I used annotations in Java too!
@mr_sat8086 Жыл бұрын
thanks for ypur lessons. I'm facing an issue. Cannot create a movie. There is a piece of the video (on 4:57 timecode) where you also face that problem, even though you choose an image, but You cut that piece of the video. Please help. Stuck in this place.
@ummehanyarozshandaanny28462 жыл бұрын
I am facing a few issues whilst I am practicing this. 1. As I have attributes already then I used annotations only for Assert [I tried the way of attributes #[Assert/NotBlank] but it's giving me an error] ... So, can I use both like this -> #[ORM\Column(length: 255)] /** * @Assert\NotBlank * @Assert\Length(min=3) */ 2. If I put this Assert on ImagePath it's not letting me to submit the form though I am uploading image. [why is this happening with me?]
@Sadiq6112 жыл бұрын
create video on collection type, dto, mapping
@codewithdary2 жыл бұрын
Will definitely do that in a later phase when I'll be creating more advanced Symfony content!
@ilyasbakirov2 жыл бұрын
Dary Update and Delete Blog Items are missing in your playlist
@codewithdary2 жыл бұрын
Added! thank you for letting me know
@hekmatyar96912 жыл бұрын
Why your entity/movie looks diferent here. in earlies movies there was atributes etc.. #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: 'integer')] private $id; #[ORM\Column(type: 'string', length: 255)] private $title; #[ORM\Column(type: 'integer')] private $releaseYear; #[ORM\Column(type: 'string', length: 255, nullable: true)] private $description; #[ORM\Column(type: 'string', length: 255)] private $imagePath; #[ORM\ManyToMany(targetEntity: Actor::class, inversedBy: 'movies')] private $actors;
@naimchowdhury5427 Жыл бұрын
1. ERROR : Expected argument of type "string", "null" given at property path "title". FIX : public function setTitle(?string $title): static { $this->title = $title ?? ''; return $this; } 2. ERROR : Expected argument of type "int", "string" given at property path "releaseYear". FIX : public function setReleaseYear($releaseYear): static { $this->releaseYear = (int) $releaseYear; return $this; }
@tryphase_be2 жыл бұрын
First off, thank you for this awesome tutorial, it's been going really good so far and i have learned a lot, but now i have run into an issue that i'm unable to solve. When i add #[Assert\NotBlank] to the $imagePath property in Entity\Movie.php, the form will no longer validate. In MovieController.php, inside the 'create' function, i added some debugging ..... $form->handleRequest($request); if ($form->isSubmitted()) { dd($form->getData()); dd($form->get('imagePath')->getData()); dd($form->isValid()); } if ($form->isSubmitted() && $form->isValid()) { ..... These are the results of each: dd($form->getData()); App\Entity\Movie {#336 ▼ -id: null -title: "test5" -releasYear: 2111 -description: "hgfhssaaaa" -imagePath: null -Actors: Doctrine\Common\Collections\ArrayCollection {#337 ▶} } dd($form->get('imagePath')->getData()); Symfony\Component\HttpFoundation\File\UploadedFile {#57 ▼ -test: false -originalName: "test.png" -mimeType: "image/png" -error: 0 path: "D:\xampp\tmp" filename: "phpC7D6.tmp" **** } dd($form->isValid()); false So, when i use $form->getData(), imagePath is null, therefore isValid returns false but when i use $form->get('imagePath')->getData(), it returns an object with the correct data When i omit the #[Assert\NotBlank] validation, the file uploads correctly when provided but returns a 500 error when left empty. I've tried using #[Assert\Type(UploadedFile::class)] but it still gives a 500 error when submitted with an empty imagePath. I have no idea how to solve this. I've tried looking into the form\getData() function, to maybe figure out how it works, but i only find the Interface, not the actual code. So i'm kinda stuck. If anyone can help me out here, that would be awesome.
@tryphase_be2 жыл бұрын
I've figured out that we explicitly instruct the formbuilder to ignore imagePath when writing the object by including 'mapped => false'. Removing that solved the issue :) I can only thank you again for an amazing tutorial. Your stuff is golden! Little things like this are also good for learning :D
@codewithdary2 жыл бұрын
Thank you Tryphase. Always makes me happy when my students find the solution theirselves :D
@ОлегК-л6й Жыл бұрын
@@tryphase_be Thank you very much. I also had a similar problem and solved it thanks to you.
@kmtsvetanov Жыл бұрын
@@tryphase_be but now for edit is broken. We need mapped false to edit buy not for create... ?