小编Luk*_*ski的帖子

为什么Symfony文件验证器不起作用

我想使用文件验证器来限制文件输入的mime类型.不幸的是,从未使用过此约束,并且所有文件都被接受

namespace WNC\SoldierBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
* WNC\SoldierBundle\Entity\Soldier
*
* @ORM\Table(name="soldier")
* @ORM\Entity(repositoryClass="WNC\SoldierBundle\Entity\SoldierRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Soldier
{

   /**
    * @var string $picture
    * @Assert\Image()
    * @ORM\Column(name="picture", type="string", length=255)
    */
    private $picture;

    /**
    * @var string $file
    * 
    * @Assert\Image()
    * @Assert\NotBlank()
    */
    public $file;


    public function getAbsolutePath()
    {
        return null === $this->picture ? null : $this->getUploadRootDir().'/'.$this->picture;
    }

    public function getWebPath()
    {
        return null === $this->picture ? null : $this->getUploadDir().'/'.$this->picture;
    }

    protected function …
Run Code Online (Sandbox Code Playgroud)

php symfony symfony-2.1

9
推荐指数
2
解决办法
6777
查看次数

标签 统计

php ×1

symfony ×1

symfony-2.1 ×1