亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何獲取具有唯一約束的錯誤消息

如何獲取具有唯一約束的錯誤消息

PHP
慕絲7291255 2022-01-08 20:03:52
我有一個表格,其中為產品添加了參考號。我已將此字段設為唯一,因為不會有重復的參考編號。我創建了一個自定義驗證器來檢查給定的引用是否已經存在,但是我收到以下錯誤:Type error: Too few arguments to function Backend\Modules\Glasses\Domain\Glasses\Validator\Constraints\DuplicateReferenceValidator::__construct(), 0 passed in /var/www/html/vendor/symfony/symfony/src/Symfony/Component/Validator/ContainerConstraintValidatorFactory.php on line 52 and exactly 1 expected我似乎無法讓我GlassesRepository在DuplicateReferenceValidator數據傳輸對象:<?phpnamespace Backend\Modules\Glasses\Domain\Glasses;use Backend\Modules\Glasses\Domain\Brand\Brand;use Backend\Modules\MediaLibrary\Domain\MediaGroup\MediaGroup;use Common\Doctrine\Entity\Meta;use Symfony\Component\Validator\Constraints as Assert;use Backend\Modules\Glasses\Domain\Glasses\Validator\Constraints as CustomAssert;class GlassesDataTransferObject{/*** Other fields ***/    /**     * @var string     *     * @Assert\NotBlank(message="err.FieldIsRequired")     * @CustomAssert\DuplicateReference     */    public $reference;/*** Other fields ***/重復引用.php<?phpnamespace Backend\Modules\Glasses\Domain\Glasses\Validator\Constraints;use Symfony\Component\Validator\Constraint;/** * @Annotation */class DuplicateReference extends Constraint{    public $message = '"{{ reference }}" already exists.';}DuplicateReferenceValidator.php<?phpnamespace Backend\Modules\Glasses\Domain\Glasses\Validator\Constraints;use Backend\Modules\Glasses\Domain\Glasses\GlassesRepository;use Symfony\Component\Validator\Constraint;use Symfony\Component\Validator\ConstraintValidator;use Symfony\Component\Validator\Exception\UnexpectedTypeException;class DuplicateReferenceValidator extends ConstraintValidator{    private $repository;    /**     * DuplicateUserValidator constructor.     */    public function __construct(GlassesRepository $repository)    {        $this->repository = $repository;    }
查看完整描述

1 回答

?
呼如林

TA貢獻1798條經驗 獲得超3個贊

我自己想通了。

我需要將實體管理器添加到我的services.yml文件中,以便能夠在驗證器中訪問它。

Backend\Modules\Glasses\Domain\Glasses\Validator\Constraints\DuplicateReferenceValidator:
        attributes:
            - "@doctrine.orm.entity_manager"


查看完整回答
反對 回復 2022-01-08
  • 1 回答
  • 0 關注
  • 170 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號