相关疑难解决方法(0)

Symfony2 - 自定义验证器和依赖注入

我试图使用依赖注入自定义验证器,以便能够使用entityManager.

我按照Symfony示例:依赖注入,但我总是收到此错误消息:

FatalErrorException:错误:在/home/milos/workspace/merrin3/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php第68行中找不到类'isdoi'

这是我的课程:

1. IsDOI课程:

    <?php
    namespace Merrin\MainBundle\Validator\Constraints;
    use Symfony\Component\Validator\Constraint;

    /**
     * @Annotation
    */
    class IsDOI extends Constraint
    {
    public $message_publisher_DOI = 'The Publisher DOI abbreviation does not correspond to the DOI you filled in !';
    public $message_journal_DOI = 'No journal found with the DOI you filled in !';
    public $journal;
    public $doiAbbreviation;

     public function validatedBy() {
            return "isdoi";
        }

        public function getTargets()
        {
            return self::CLASS_CONSTRAINT;
        }
    }
Run Code Online (Sandbox Code Playgroud)

2. IsDOIValidator类:

<?php

namespace Merrin\MainBundle\Validator\Constraints;

use Doctrine\ORM\EntityManager;
use Symfony\Component\Validator\Constraint; …
Run Code Online (Sandbox Code Playgroud)

php dependency-injection customvalidator symfony

2
推荐指数
1
解决办法
6597
查看次数