数据库

时间:2018-02-26 14:58:36

标签: php symfony file-upload symfony-2.7

我试图以symfony2格式上传excel文件,但没有给出任何错误,它没有在此字段中插入任​​何内容。其他字段填写在我的数据库中。有人有想法吗?

我有一个表格文件和一个带有字段delivery_list_id的表格订单,指的是文件的ID。至少,这就是想法。

这是实体部分:

/**
 * @var File
 * @ORM\ManyToOne(targetEntity="Myapp\Bundle\CoreBundle\Entity\File", cascade={"persist", "remove"})
 * @ORM\JoinColumn(referencedColumnName="id", nullable=true)
 */
private $deliveryList;

/**
 * @var UploadedFile
 *
 * @Assert\File(
 *     mimeTypes = {"application/vnd.ms-excel", "application/vnd.ms-office", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "text/plain", "text/csv", "application/octet-stream"},
 *     mimeTypesMessage = "The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}"
 * )
 */
private $uploadedDeliveryList;

/**
 * @return File
 */
public function getDeliveryList()
{
    return $this->deliveryList;
}

/**
 * @param File $deliveryList
 */
public function setDeliveryList($deliveryList)
{
    $this->deliveryList = $deliveryList;
}

/**
 * @return UploadedFile
 */
public function getUploadedDeliveryList()
{
    return $this->uploadedDeliveryList;
}

/**
 * @param UploadedFile $uploadedDeliveryList
 *
 * @return $this
 */
public function setUploadedDeliveryList($uploadedDeliveryList)
{
    $this->uploadedDeliveryList = $uploadedDeliveryList;

    return $this;
}

这是树枝的一部分:

$builder
                ->add('uploadedDeliveryList', 'bootstrap_file', array(
                    'initialCaption' => 'Please select an excelfile or csv file',
                    'file' => $order->getDeliveryList(),
                    'initialPreview' => ($order->getDeliveryList() ? '<a type="button" data-toggle="modal" data-target=".preview_' . $order->getDeliveryList()->getId() . '"><img src="' . $this->router->generate('file_thumbnail', ['id' => $order->getDeliveryList()->getId()]) . '" alt="preview"></a>' : ''),
                    'label' => 'Upload a delivery list',
                    'attr' => array(
                        'class' => 'col-sm-12 file',
                        'accept' => 'application/vnd.ms-excel, application/vnd.ms-office, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, text/plain, text/csv, application/octet-stream'
                    ),
                    'required' => false,
                )
            );

我的表单有

enctype="multipart/form-data"

任何人都知道为什么它会更新我的订单表中的所有内容,但不会将文件插入文件表中(也不会在我的订单表中插入delivery_list_id)?

这是我的上传处理程序,他将文件写入服务器,但没有进行数据库更新。即使脚本通过那里也没有给出错误。 如果我在我的实体setDeliveryList中设置了一个骰子(&#39; in&#39;);它似乎没有进入那里。

public function handleUploadedFiles(Event $event)
{
    $order = $event->getOrder();
    if ($uploadedDeliveryList = $order->getUploadedDeliveryList()) {
        $file = $this->transformUploadedFileToFile('/' . $order->getClient()->getId() . '/order/' . $order->getNumber() . '/deliverylist', $uploadedDeliveryList, $order->getDeliveryList());
        $file->setClient($order->getClient());
        $order->setDeliveryList($file);
    }
}

0 个答案:

没有答案