2

これは私のコントローラーです-ドキュメントから直接

<?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;
    }
}

フォームを送信すると、次のエラーが表示されます。

'INSERT INTO files (path, name, mime_type, size) VALUES (?, ?, ?, ?)' を params [null, "asdasdasd", null, null] で実行中に例外が発生しました:

SQLSTATE[23000]: 整合性制約違反: 1048 列 'path' は null にできません

私が正しければ、アップロード可能な拡張機能は、ファイル エンティティにイベントの正しいデータを入力する必要がありますか? 私は正しい?

4

0 に答える 0