Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File update : Argument 1 [...] must be a File #329

Closed
bonswouar opened this issue Oct 28, 2014 · 2 comments
Closed

File update : Argument 1 [...] must be a File #329

bonswouar opened this issue Oct 28, 2014 · 2 comments
Labels

Comments

@bonswouar
Copy link

While I was going to implement the solution to be able to update Files in an Entity (#8 (comment)), I noticed an Error when I handle my update Form :

Catchable Fatal Error: Argument 1 passed to VENDOR\Bundle\Entity\MyEntity::setImage() must be an instance of Symfony\Component\HttpFoundation\File\File, null given

To fix that I can change that :

public function setImage(File $image)
{
    $this->image = $image;

    return $this;
}

to that :

public function setImageTexte($image)
{
    $this->image = $image;

    return $this;
}

But I guess if that's the solution it would be in the documentation, did I do something wrong ?

By the way, here are my properties :

/**
 * @Vich\UploadableField(mapping="article_image", fileNameProperty="imagePath")
 *
 * Note : This is not a mapped field of entity metadata, just a simple property.
 *
 * @var File $image
 *
 * @Assert\File(maxSize="6000000", mimeTypes={"image/jpeg", "image/png"})
 */
public $image;


/**
 * @var string
 *
 * @ORM\Column(name="image_path", type="string", length=45)
 */
private $imagePath;
@K-Phoen
Copy link
Collaborator

K-Phoen commented Nov 4, 2014

Just change your method definition like this:

public function setImage(File $image = null)

@K-Phoen K-Phoen closed this as completed Nov 4, 2014
@K-Phoen K-Phoen added the Support label Nov 4, 2014
@Abdelmonem-BEN-NACEUR
Copy link

@K-Phoen you saved my time. Thank you ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants