gpt4 book ai didi

file - Symfony - 找不到文件

转载 作者:行者123 更新时间:2023-12-02 08:13:38 25 4
gpt4 key购买 nike

实体具有 nullable=true。表格有必填= false。生成的 HTML 没有任何要求。

当我离开文件输入时出现错误:

The file could not be found.

说实话,我不知道我应该在哪里寻找...;)

public function updateAction(Request $request, $id)
{

$em = $this->getDoctrine()->getManager();

$entity = $em->getRepository('FortiCoreBundle:Article')->find($id);

if (!$entity) {
throw $this->createNotFoundException('Unable to find Article entity.');
}

$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
// $editForm->isVail() false because have error The file could not be found.
if ($editForm->isValid()) {

实体文件:

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

/**
* @var string
*
* @Assert\File(
* maxSize="3M",
* mimeTypes={"image/png", "image/jpeg", "image/pjpeg"}
* )
*
* @ORM\Column(name="filename", type="string", nullable=true)
* @Gedmo\UploadableFileName
*/
private $filename;

public function uploadPath()
{
return 'images/article/' . date('Y') . '/' . date('m');
}

public function getRelativePath()
{
if (empty($this->filename)) {
return null;
} else {
return $this->uploadPath() . '/' . $this->filename;
}
}

/**
* Set filename
*
* @param string $filename
* @return Article
*/
public function setFilename($filename)
{
if (!is_null($filename)) {
$this->filename = $filename;
}

return $this;
}

/**
* Get filename
*
* @return string
*/
public function getFilename()
{
return $this->filename;
}

和 FormType 文件:

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
//...
->add('filename', 'file', array(
'label' => 'Zdjęcie',
'required' => false,
'data_class' => null,
'attr' => array(
"class" => 'no-border btn-xs')
))
//...
;
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Forti\CoreBundle\Entity\Article'
));
}

public function getName()
{
return 'forti_corebundle_articletype';
}

最佳答案

我知道我迟到了,但是解决我的问题的是我在表单中缺少以下内容

enctype="multipart/form-data"

 <form method="post" action="{{ path('your_route_name') }}" novalidate enctype="multipart/form-data">

关于file - Symfony - 找不到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28774228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com