持久stof教义扩展uploadble时出错。 Symfony 2.3

时间:2015-01-03 18:29:07

标签: symfony doctrine-orm doctrine-uploadable

这是我的控制器 - 直接来自文档

<?php

namespace Votes\VotesBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Votes\VotesBundle\Entity\File as File;

class FileController extends Controller
{

    /**
     * @Template()
     */
    public function newAction()
    {
        $file = new File();
        $form = $this->createFormBuilder($file)
            ->add('name')
            ->add('file','file')
            ->getForm()
        ;

        if ($this->getRequest()->getMethod() === 'POST') {
            $form->bind($this->getRequest());

            if ($form->isValid()) {
                $em = $this->getDoctrine()->getManager();

                $em->persist($file);

                $uploadableManager = $this->get('stof_doctrine_extensions.uploadable.manager');

                // Here, "getMyFile" returns the "UploadedFile" instance that the form bound in your $myFile property
                $uploadableManager->markEntityToUpload($file, $file->getFile());

                $em->flush();

                $this->redirect($this->generateUrl('/file/new'));
            }
        }

        return array('form' => $form->createView());

    }

}

这是我的文件实体

<?php
se Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
 * File
 *
 * @ORM\Table(name="files")
 * @ORM\Entity
 * @Gedmo\Uploadable( allowOverwrite=true, appendNumber=true, filenameGenerator="SHA1")
 */
class File
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

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

    /**
     * @ORM\Column(name="name", type="string")
     * @Gedmo\UploadableFileName
     */
    private $name;

    /**
     * @ORM\Column(name="mime_type", type="string")
     * @Gedmo\UploadableFileMimeType
     */
    private $mimeType;

    /**
     * @ORM\Column(name="size", type="decimal")
     * @Gedmo\UploadableFileSize
     */
    private $size;

    private $file;

    public function setFile($file)
    {
        $this->file = $file;

        return $this;
    }

    public function getFile()
    {
        return $this->file;
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set path
     *
     * @param string $path
     * @return File
     */
    public function setPath($path)
    {
        $this->path = $path;

        return $this;
    }

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

    /**
     * Set name
     *
     * @param string $name
     * @return File
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

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

    /**
     * Set mimeType
     *
     * @param string $mimeType
     * @return File
     */
    public function setMimeType($mimeType)
    {
        $this->mimeType = $mimeType;

        return $this;
    }

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

    /**
     * Set size
     *
     * @param string $size
     * @return File
     */
    public function setSize($size)
    {
        $this->size = $size;

        return $this;
    }

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

提交表单时出现此错误:

执行&#39; INSERT INTO文件(路径,名称,mime_type,大小)VALUES(?,?,?,?)&#39;用params [null,&#34; asdasdasd&#34;,null,null]:

SQLSTATE [23000]:完整性约束违规:1048列&#39;路径&#39;不能为空

如果我正确 - 可上传的扩展程序 - 必须填写我的文件实体 事件中的正确数据?我对吗?

0 个答案:

没有答案