我正在维护一个大型项目。我们最近将框架更新到5.2版,并得到一个错误: Argument 1 passed to Symfony\Component\Security\Core\Encoder\MigratingPasswordEncoder::encodePassword() must be of the type string, null given, called in ... 下面是buildForm()方法的外观: $builder
->setMethod('POST')
// ....
->add(
我有一个简单的表格,有两个字段,电子邮件和名字。电子邮件在帐户实体中,名称在子实体中: MedicalCenters
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constra
我使用Symfony v5.2,我已经创建了这个约束: $constraint = new Assert\Collection([
'firstname' => [
new Assert\NotNull(),
new Assert\NotBlank()
],
'lastname' => [
new Assert\NotNull(),
new Asser
我想在基于复选框值的表单中验证输入密码字段。如果该值为真,则密码字段应为NOTBlank和等于第一到第二。这就是我到目前为止所拥有的:
namespace App\Form;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\E
管理员将能够编辑他的网站的用户,但不能密码。所以我创建了这个EditUserFormType:
namespace CAPUserBundle\Form\Type;
use CAPShopAdminBundle\Repository\DiscountGridRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\C
因此,在我的表单中,我有一个字段可以插入密码。在表单生成器中的字段中,我添加了2个约束;一个用于表示字段为空,另一个用于密码太短。
new NotBlank([
'message' => 'reset.password.error.enterpassword',
]),
new Length([
'min' => 6,
'minMessage' => 'reset.password.error.passwordtooshort',
// max length all
我正在构建一个自定义验证器,它需要验证db中两个表单域的值,以便通过此约束。
我的问题是:ContractValidator的validation方法的签名中只有一个$value,那么我如何访问多个字段中的值来进行验证呢?
下面是一个典型的自定义验证器:
namespace Acme\WebsiteBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class MyCustomValidat
我是symfony表单类型的新手。我遇到这样一种情况,在表单中我需要包含更改密码功能我的表单类型如下所示 <?php
namespace App\Form;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Image
嗨,在管理系统上工作。我想在运行@SecurityAssert之前运行验证约束"NotBlank“。(否则会有不必要的数据库命中,用户是否会收到两条不同的错误消息)?谢谢!
use Symfony\Component\Security\Core\Validator\Constraints as SecurityAssert;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Constraints\NotBlank;
class
namespace Topxia\LiftBundle\Form;
use Symfony\Component\Validator\Constraint as Assert;
class AddUser {
/**
* @Assert\NotBlank(message="用户名不能为空")
*/
public $username;
/**
* @Assert\NotBlank(message="用户姓名不能为空")
*/
public $name;
/**
* @
我对symfony验证有个问题。将NotBlank或Length添加到实体后,验证将显示有关缺少值的标准消息(默认消息NotBlank)。而不管该字段是否已填充。
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\OneToOne;
use Symfony\Component\Validator\Constraints as Assert;
class Employee
{
/**
我的问题涉及用户表单中的一个字段,即用户名。由于断言验证适用于实体中的其他字段,因此我发现这样的行为很奇怪-跳过我为用户实体中的用户名属性指出的断言规则,并将null属性传递给userFormNewHandler,这会产生错误,特别是当我发现它与其他字段没有什么不同的时候。我在想,我错过了什么? UserType.php: <?php
namespace App\UserBundle\Form\Type;
use App\UserBundle\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Compo
我有联系人表单,主题应该至少有5个字符,但当我在此字段中填写一个字符并提交表单时,我看不到任何错误,为什么,有什么问题?
WebsiteController.php:
namespace Acme\WebsiteBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Acme\WebsiteBundle\Contact\ContactForm;
use Acme\WebsiteBundle\Co
我在Symfony 之后开发了一个基本的用户注册表单。当试图提交密码和失败的登录计数不能为空的表单时,我正在收到验证错误:
data.password This value should not be null
data.failedLogins This value should not be null
RegistrationFormType类:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('first
我正在跟踪由皮奥特朱拉。
我有这样一个用户实体
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\U
我得到了这个错误:
消息:“语义错误--属性用户中的注释"@Symfony\Component\Validator\Constraints\Length”::$name不存在,或者无法自动加载。“
,这是Github 上的代码
use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Constraints as Assert;
class User {
/**
* @Assert\Length(min = 3)
* @Assert\NotBlank
当我向整型字段添加了NotBlank和类型验证时,在验证表单组件时遇到问题。
我的validation.yml如下所示:
Acme\StoreBundle\Entity\Foo:
properties:
bar:
- NotBlank:
message: You must specify a bar
- Type:
type: integer
message: bar must be an integer
我的FormType文件如下所示:
$builder->add
文档说,'notBlank'是您希望确保字段不为空的验证规则,就像在!empty($somevalue)中一样,但是当我将字段留为空(‘)或者当我在字段('s0meCraZyPasSworD')中放置值时,它仍然显示错误消息?
有人能看出我做错了什么吗?其余的验证就像minlength一样工作,但是为了更好地了解为什么'notBlank'似乎不起作用,我把它们注释掉了。
CONTROLLER:
// Set of validation rules to be run
$validateRules = [
'fieldList
我正在用Symfony创建一个表单,它的工作非常完美,但是我的验证有问题,我创建了一个必需的字段,而不是空白,但是当我提交输入为空的表单时,错误消息不会显示,我不知道为什么
代码中有一些部分:
FormType:
use Symfony\Component\Validator\Constraints\NotBlank;
class AnnonceurType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$bui
我有一个带有Assert回调方法"processSignup“的实体帐户。只有当登录约束和密码约束成功时,我才会调用"processSignup“。请问如何在我的processSignup方法中检查这个?
<?php
namespace MyProject\Bundle\FrontBundle\Entity;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\ExecutionContext;
use Symfony\Component\Validator\Cons
我有表格。例如,它的登录表单:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('phone', TextType::class, [
'constraints' => [
new NotBlank(),
new Type(['type' => 'string']),
new Length(