symfony 相关问题

Symfony既指用于构建Web应用程序的PHP框架,也指构建框架的一组组件。此标记指的是当前支持的主要版本2.x,3.x和4.x.或者,您可以使用相应的标记指定确切的版本。此标记不应用于有关Symfony 1.x的问题。请改用Symfony1标签。

如何使用属性#[Embedded]嵌入具有学说的对象集合?

假设我们有一个简单的实体 User ,其中包含属性 $address ,并且该实体包含一组 Address 对象,如何使用原则(doc)来做到这一点? 这是我的测试: 假设我们有一个简单的实体User,其中包含一个属性$address,并且该实体包含一组Address对象,如何使用学说(doc)来做到这一点? 这是我的测试: <?php use Doctrine\ORM\Mapping\Embeddable; use Doctrine\ORM\Mapping\Embedded; #[Embeddable] class Address { private string $name; } class User { #[Embedded(class: Address::class.'[]')] private array $address; } 在这个例子中,这不起作用,因为当我检索 User 的记录时,属性 $address 只表示一个二维数组,而不是 Address 实例的数组。 在class User的定义中,这是你的错误。 private array $address; 这应该是: private Address $address;

回答 1 投票 0

使用 [#Assert\Choice] 验证枚举类型

我正在尝试验证自定义 DTO 类中的枚举类型。我正在尝试使用 Symfony #[Assert\Choice] 属性,但如果我传递错误的值,它似乎不起作用。 自定义 DTO: #[断言\Ch...

回答 3 投票 0

Symfony 如何在 base.html.twig 上包含控制器

我有一个小问题,我是 symfony 的新手,我创建了一个控制器和一个菜单模板,我想将其集成到我的 base.html.twig 中。 我绝对需要调用控制器,因为我...

回答 3 投票 0

导致TerminateProcess的原因:访问被拒绝。当尝试在 Windows 上运行 Symfony 服务器时?

上下文 我正在使用 Symfony 开发一个网站,并花了大约两周的时间来完成它。 我使用的是 Windows 10,我使用 Symfony 5.8.12 和 php 8.1.13 以及 Wamp 3.3.0 作为数据库。 一切顺利

回答 1 投票 0

实时组件从子集合更新父模型

我正在实现一个包含子组件集合的 LiveComponent。一切工作大部分都很好,但如果更新的属性是一个数组,我不知道如何更新父模型。 我...

回答 1 投票 0

向 Symfony 6 表单生成器添加具有 2 种不同类型的表单字段

->add('useExtendedCustomer', CheckboxType::class, [ 'label' => '创建新客户?', '映射' => 假, '必需' => 假, ...

回答 1 投票 0

MongoDB DocumentManager 和 Persistence ManagerRegistry 中 getRepository() 函数的兼容性问题

我收到此错误: 编译错误:Doctrine\ODM\MongoDB\DocumentManager::getRepository($className) 的声明必须与 Doctrine\Persistence\ManagerRegistry::getRepository(st...

回答 1 投票 0

Gitlab CI Symfony:SQLSTATE[HY000] [2002] 连接被拒绝

每次有人推送代码时,我都会使用 gitlab 来运行单元测试。我在安装 Composer 时遇到此错误。 > Incenteev\ParameterHandler\ScriptHandler::buildParameters 创建“应用程序/配置/

回答 2 投票 0

使用 symfony 序列化器组也不起作用

我正在使用slim4框架和php8.3开发一个应用程序。 我安装了 symfony 序列化器来序列化/反序列化我的对象。 这就是我像依赖项一样创建序列化器的方式: 依赖...

回答 1 投票 0

Symfony 6 / PropertyAccessor 需要对对象或数组进行操作,但在尝试遍历路径时发现类型“NULL”

我需要一些帮助,我一个月来就面临这个问题并尝试解决它(已经在很多论坛上搜索过,但没有任何效果)。 这是我的错误屏幕 PropertyAccessor 需要一张...

回答 1 投票 0

已解决 Symfony 6 / PropertyAccessor 需要对对象或数组进行操作,但在尝试遍历路径时发现类型“NULL”

我需要一些帮助,我一个月来就面临这个问题并尝试解决它(已经在很多论坛上搜索过,但没有任何效果)。 这是我的错误屏幕 PropertyAccessor 需要一张...

回答 1 投票 0

属性路径“id_autoridad”给出的预期参数类型为“int”、“App\Entity\Autoridad”

当我在 symofny 6 上工作时,我想执行此表单: 当我正在开发 symofny 6 时,我想执行此表单: <?php namespace App\Form; use App\Entity\Autoridad; use App\Entity\BalanceAnual; use Doctrine\DBAL\Types\IntegerType; use Doctrine\ORM\EntityRepository; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class BalanceAnualType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options): void { $id_partido = $options['id_partido']; $autoridades = $options['autoridades']; #dd($id_partido); $builder ->add('id_partido') ->add('presentacion_anual') ->add('ejercicio') ->add('dia_cierre_ejercicio') ->add('mes_cierre_ejercicio') ->add('anio_ejercicio') ->add('fecha_presentacion') ->add('aprobacion',ChoiceType::class, ['choices' => [ 'SI' => 'S', 'NO' => 'N', ]]) ->add('fecha_aprobacion') ->add('id_autoridad', ChoiceType::class,[ 'choices'=> $autoridades, 'choice_label' => function ($autoridad) { if(strlen($autoridad->getApellido_Nombre())> 0){ echo("<script>console.log('idAutoridad: " . $autoridad->getId() ."');</script>"); return $autoridad->getApellido_Nombre(); }elseif(strlen($autoridad->getNombre())> 0){ echo("<script>console.log('idAutoridad: " . $autoridad->getId() ."');</script>"); return $autoridad->getNombre() ." ".$autoridad->getApellido(); }else{ return $autoridad->getId(); } }, 'choice_value' =>'id' ]) ->add('firmante_balance') ->add('movimentos',ChoiceType::class, ['choices' => [ 'SI' => 'S', 'NO' => 'N', ]]) ; } public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'data_class' => BalanceAnual::class, 'id_partido' => null, 'autoridades' => null, ]); } } 表单以我想要的方式显示所有信息,但是当我想推送数据时,我收到以下错误:属性路径“id_autoridad”给出的预期参数类型为“int”,“App\Entity\Autoridad”。 我的实体: <?php namespace App\Entity; use App\Repository\BalanceAnualRepository; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: BalanceAnualRepository::class)] class BalanceAnual { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\Column()] private ?int $id_partido = null; #[ORM\Column()] private ?int $presentacion_anual = null; #[ORM\Column] private ?int $ejercicio = null; #[ORM\Column(length: 2)] private ?int $dia_cierre_ejercicio = null; #[ORM\Column(length: 2)] private ?int $mes_cierre_ejercicio = null; #[ORM\Column(length: 4)] private ?int $anio_ejercicio = null; #[ORM\Column(type: Types::DATE_MUTABLE)] private ?\DateTimeInterface $fecha_presentacion = null; #[ORM\Column(length: 1)] private ?string $aprobacion = null; #[ORM\Column(type: Types::DATE_MUTABLE)] private ?\DateTimeInterface $fecha_aprobacion = null; #[ORM\Column] private ?int $id_autoridad = null; #[ORM\Column(length: 100)] private ?string $firmante_balance = null; #[ORM\Column(length: 1)] private ?string $movimentos = null; /*#[ORM\ManyToOne(targetEntity: Autoridad::class)] #[ORM\JoinColumn(name: 'id_autoridad', referencedColumnName: 'id')] private $autoridad; #[ORM\ManyToOne(targetEntity: Partido::class)] #[ORM\JoinColumn(name: 'id_partido', referencedColumnName: 'id')] private $partido;*/ public function getId(): ?int { return $this->id; } public function getId_Partido(): ?int{ return $this->id_partido; } public function setId_Partido(int $id_partido): static { $this->id_partido=$id_partido; return $this; } public function getIdPartido(): ?int { return $this->id_partido; } public function setIdPartido(int $id_partido): static { $this->id_partido = $id_partido; return $this; } public function getPresentacion_Anual(): ?string { return $this->presentacion_anual; } public function setPresentacion_Anual(string $presentacion_anual): static { $this->presentacion_anual = $presentacion_anual; return $this; } public function getPresentacionAnual(): ?string { return $this->presentacion_anual; } public function setPresentacionAnual(string $presentacion_anual): static { $this->presentacion_anual = $presentacion_anual; return $this; } public function getEjercicio(): ?int { return $this->ejercicio; } public function setEjercicio(int $ejercicio): static { $this->ejercicio = $ejercicio; return $this; } public function getDia_Cierre_Ejercicio(): ?int { return $this->dia_cierre_ejercicio; } public function setDia_Cierre_Ejercicio(int $dia_cierre_ejercicio): static { $this->dia_cierre_ejercicio = $dia_cierre_ejercicio; return $this; } public function getDiaCierreEjercicio(): ?int { return $this->dia_cierre_ejercicio; } public function setDiaCierreEjercicio(int $dia_cierre_ejercicio): static { $this->dia_cierre_ejercicio = $dia_cierre_ejercicio; return $this; } public function getMes_cierre_ejercicio(): ?int { return $this->mes_cierre_ejercicio; } public function setMes_cierre_ejercicio(int $mes_cierre_ejercicio): static { $this->mes_cierre_ejercicio = $mes_cierre_ejercicio; return $this; } public function getMesCierreEjercicio(): ?int { return $this->mes_cierre_ejercicio; } public function setMesCierreEjercicio(int $mes_cierre_ejercicio): static { $this->mes_cierre_ejercicio = $mes_cierre_ejercicio; return $this; } public function getAnio_Ejercicio(): ?int { return $this->anio_ejercicio; } public function setAnio_Ejercicio(int $anio_ejercicio): static { $this->anio_ejercicio = $anio_ejercicio; return $this; } public function getAnioEjercicio(): ?int { return $this->anio_ejercicio; } public function setAnioEjercicio(int $anio_ejercicio): static { $this->anio_ejercicio = $anio_ejercicio; return $this; } public function getFecha_Presentacion(): ?\DateTimeInterface { return $this->fecha_presentacion; } public function setFecha_Presentacion(\DateTimeInterface $fecha_presentacion): static { $this->fecha_presentacion = $fecha_presentacion; return $this; } public function getFechaPresentacion(): ?\DateTimeInterface { return $this->fecha_presentacion; } public function setFechaPresentacion(\DateTimeInterface $fecha_presentacion): static { $this->fecha_presentacion = $fecha_presentacion; return $this; } public function getAprobacion(): ?string { return $this->aprobacion; } public function setAprobacion(string $aprobacion): static { $this->aprobacion = $aprobacion; return $this; } public function getFecha_Aprobacion(): ?\DateTimeInterface { return $this->fecha_aprobacion; } public function setFecha_Aprobacion(\DateTimeInterface $fecha_aprobacion): static { $this->fecha_aprobacion = $fecha_aprobacion; return $this; } public function getFechaAprobacion(): ?\DateTimeInterface { return $this->fecha_aprobacion; } public function setFechaAprobacion(\DateTimeInterface $fecha_aprobacion): static { $this->fecha_aprobacion = $fecha_aprobacion; return $this; } public function getId_autoridad(): ?int { return $this->id_autoridad; } public function setId_autoridad(int $id_autoridad): static { $this->id_autoridad = $id_autoridad; return $this; } public function getIdAutoridad(): ?int { return $this->id_autoridad; } public function setIdAutoridad(int $id_autoridad): static { $this->id_autoridad = $id_autoridad; return $this; } public function getFirmante_Balance(): ?string { return $this->firmante_balance; } public function setFirmante_Balance(string $firmante_balance): static { $this->firmante_balance = $firmante_balance; return $this; } public function getFirmanteBalance(): ?string { return $this->firmante_balance; } public function setFirmanteBalance(string $firmante_balance): static { $this->firmante_balance = $firmante_balance; return $this; } public function getMovimentos(): ?string { return $this->movimentos; } public function setMovimentos(string $movimentos): static { $this->movimentos = $movimentos; return $this; } } 我的控制器: #[Route('/{idPartido}/detalle/new', name: 'app_balance_anual_new', methods: ['GET', 'POST'])] public function new($idPartido,Request $request, EntityManagerInterface $entityManager): Response { $id_partido = intval($idPartido); $balanceAnual = new BalanceAnual(); $autoridades = $entityManager->getRepository(Autoridad::class)->findBy(['id_partido' => $id_partido]); #dd($autoridades); $form = $this->createForm(BalanceAnualType::class, $balanceAnual, ['id_partido' => $idPartido, 'autoridades' => $autoridades]); $form->get('id_partido')->setData($idPartido); #dd($form->getData(), $form->getErrors()); // print_r($request); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { //dd($balanceAnual); $value = $form->get('id_autoridad')->getData(); $balanceAnual->setIdAutoridad($value); $entityManager->persist($balanceAnual); #dd($balanceAnual); $entityManager->flush(); return $this->redirectToRoute('app_balance_anual_index', ['idPartido' => $idPartido,], Response::HTTP_SEE_OTHER); } return $this->render('balance_anual/new.html.twig', [ 'balance_anual' => $balanceAnual, 'idPartido' => $idPartido, 'form' => $form, ]); } 另外两个实体:Partido: <?php namespace App\Entity; use App\Repository\PartidoRepository; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: PartidoRepository::class)] class Partido { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\Column(length: 100)] private ?string $nombre = null; #[ORM\Column] private ?int $numero = null; #[ORM\Column(length: 1)] private ?string $ambito = null; #[ORM\Column(length: 100)] private ?string $domicilio = null; #[ORM\Column] private ?int $id_localidad = null; #[ORM\Column(length: 255)] private ?string $domicilio_partidario = null; #[ORM\Column] private ?int $id_localidad_domicilio_partidario = null; #[ORM\Column(length: 100)] private ?string $telefono = null; #[ORM\Column(length: 100)] private ?string $email = null; #[ORM\Column(length: 1)] private ?string $tipo = null; #[ORM\Column(length: 2)] private ?string $estado = null; #[ORM\Column(length: 255)] private ?string $observaciones = null; #[ORM\Column(length: 1)] private ?string $libros = null; #[ORM\Column(length: 1)] private ?string $tipo_firma = null; #[ORM\Column(type: Types::DATE_MUTABLE)] private ?\DateTimeInterface $fecha_presentacion = null; #[ORM\Column] private ?int $id_localidad_ambito = null; #[ORM\Column] private ?int $id_auto_provisorio = null; #[ORM\Column(type: Types::DATE_MUTABLE)] private ?\DateTimeInterface $notificacion_auto_provisorio = null; #[ORM\Column(type: Types::DATE_MUTABLE)] private ?\DateTimeInterface $publicacion_boletin_oficial = null; #[ORM\Column] private ?int $id_auto_definitivo = null; #[ORM\Column(type: Types::DATE_MUTABLE)] private ?\DateTimeInterface $notificacion_auto_definitivo = null; #[ORM\Column] private ?int $id_auto_caducidad = null; #[ORM\Column(length: 255)] private ?string $observacion_caducidad = null; #[ORM\Column] private ?int $id_expediente = null; #[ORM\Column] private ?int $renueva_interna = null; #[ORM\Column] private ?int $id_extincion = null; #[ORM\Column] private ?int $codigo_postal = null; #[ORM\Column] private ?int $anio_exp_electronico = null; #[ORM\Column] private ?int $nro_exp_electronico = null; #[ORM\Column(type: Types::BIGINT)] private ?string $cuil_apoderado_notif = null; public function getId(): ?int { return $this->id; } public function getNombre(): ?string { return $this->nombre; } public function setNombre(string $nombre): static { $this->nombre = $nombre; return $this; } public function getNumero(): ?int { return $this->numero; } public function setNumero(int $numero): static { $this->numero = $numero; return $this; } public function getAmbito(): ?string { return $this->ambito; } public function setAmbito(string $ambito): static { $this->ambito = $ambito; return $this; } public function getDomicilio(): ?string { return $this->domicilio; } public function setDomicilio(string $domicilio): static { $this->domicilio = $domicilio; return $this; } public function getIdLocalidad(): ?int { return $this->id_localidad; } public function getId_Localidad(): ?int { return $this->id_localidad; } public function setIdLocalidad(int $id_localidad): static { $this->id_localidad = $id_localidad; return $this; } public function getDomicilioPartidario(): ?string { return $this->domicilio_partidario; } public function setDomicilioPartidario(string $domicilio_partidario): static { $this->domicilio_partidario = $domicilio_partidario; return $this; } public function getIdLocalidadDomicilioPartidario(): ?int { return $this->id_localidad_domicilio_partidario; } public function setIdLocalidadDomicilioPartidario(int $id_localidad_domicilio_partidario): static { $this->id_localidad_domicilio_partidario = $id_localidad_domicilio_partidario; return $this; } public function getTelefono(): ?string { return $this->telefono; } public function setTelefono(string $telefono): static { $this->telefono = $telefono; return $this; } public function getEmail(): ?string { return $this->email; } public function setEmail(string $email): static { $this->email = $email; return $this; } public function getTipo(): ?string { return $this->tipo; } public function setTipo(string $tipo): static { $this->tipo = $tipo; return $this; } public function getEstado(): ?string { return $this->estado; } public function setEstado(string $estado): static { $this->estado = $estado; return $this; } public function getObservaciones(): ?string { return $this->observaciones; } public function setObservaciones(string $observaciones): static { $this->observaciones = $observaciones; return $this; } public function getLibros(): ?string { return $this->libros; } public function setLibros(string $libros): static { $this->libros = $libros; return $this; } public function getTipoFirma(): ?string { return $this->tipo_firma; } public function setTipoFirma(string $tipo_firma): static { $this->tipo_firma = $tipo_firma; return $this; } public function getFechaPresentacion(): ?\DateTimeInterface { return $this->fecha_presentacion; } public function setFechaPresentacion(\DateTimeInterface $fecha_presentacion): static { $this->fecha_presentacion = $fecha_presentacion; return $this; } public function getIdLocalidadAmbito(): ?int { return $this->id_localidad_ambito; } public function setIdLocalidadAmbito(int $id_localidad_ambito): static { $this->id_localidad_ambito = $id_localidad_ambito; return $this; } public function getIdAutoProvisorio(): ?int { return $this->id_auto_provisorio; } public function setIdAutoProvisorio(int $id_auto_provisorio): static { $this->id_auto_provisorio = $id_auto_provisorio; return $this; } public function getNotificacionAutoprovisorio(): ?\DateTimeInterface { return $this->notificacion_auto_provisorio; } public function setNotificacionAuto_provisorio(\DateTimeInterface $notificacion_auto_provisorio): static { $this->notificacion_auto_provisorio = $notificacion_auto_provisorio; return $this; } public function getPublicacionBoletinOficial(): ?\DateTimeInterface { return $this->publicacion_boletin_oficial; } public function setPublicacionBoletinOficial(\DateTimeInterface $publicacion_boletin_oficial): static { $this->publicacion_boletin_oficial = $publicacion_boletin_oficial; return $this; } public function getIdAutoDefinitivo(): ?int { return $this->id_auto_definitivo; } public function setIdAutoDefinitivo(int $id_auto_definitivo): static { $this->id_auto_definitivo = $id_auto_definitivo; return $this; } public function getNotificacionAutoDefinitivo(): ?\DateTimeInterface { return $this->notificacion_auto_definitivo; } public function setNotificacionAutoDefinitivo(\DateTimeInterface $notificacion_auto_definitivo): static { $this->notificacion_auto_definitivo = $notificacion_auto_definitivo; return $this; } public function getIdAutoCaducidad(): ?int { return $this->id_auto_caducidad; } public function setIdAutoCaducidad(int $id_auto_caducidad): static { $this->id_auto_caducidad = $id_auto_caducidad; return $this; } public function getObservacionCaducidad(): ?string { return $this->observacion_caducidad; } public function setObservacionCaducidad(string $observacion_caducidad): static { $this->observacion_caducidad = $observacion_caducidad; return $this; } public function getIdExpediente(): ?int { return $this->id_expediente; } public function setIdExpediente(int $id_expediente): static { $this->id_expediente = $id_expediente; return $this; } public function getRenuevaInterna(): ?int { return $this->renueva_interna; } public function setRenuevaInterna(int $renueva_interna): static { $this->renueva_interna = $renueva_interna; return $this; } public function getIdExtincion(): ?int { return $this->id_extincion; } public function setIdExtincion(int $id_extincion): static { $this->id_extincion = $id_extincion; return $this; } public function getCodigoPostal(): ?int { return $this->codigo_postal; } public function setCodigoPostal(int $codigo_postal): static { $this->codigo_postal = $codigo_postal; return $this; } public function getAnioExpElectronico(): ?int { return $this->anio_exp_electronico; } public function setAnioExpElectronico(int $anio_exp_electronico): static { $this->anio_exp_electronico = $anio_exp_electronico; return $this; } public function getNroExpElectronico(): ?int { return $this->nro_exp_electronico; } public function setNroExpElectronico(int $nro_exp_electronico): static { $this->nro_exp_electronico = $nro_exp_electronico; return $this; } public function getCuilApoderadoNotif(): ?string { return $this->cuil_apoderado_notif; } public function setCuilApoderadoNotif(string $cuil_apoderado_notif): static { $this->cuil_apoderado_notif = $cuil_apoderado_notif; return $this; } } 自动驾驶: <?php namespace App\Entity; use App\Repository\AutoridadRepository; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: AutoridadRepository::class)] class Autoridad { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\Column] private ?int $documento = null; #[ORM\Column(length: 1)] private ?string $sexo = null; #[ORM\Column(length: 10)] private ?string $tipo = null; #[ORM\Column(length: 200)] private ?string $apellido_nombre = null; #[ORM\Column(length: 100)] private ?string $apellido = null; #[ORM\Column(length: 100)] private ?string $nombre = null; #[ORM\Column(length: 100)] private ?string $domicilio = null; #[ORM\Column(length: 50)] private ?string $telefono = null; #[ORM\Column(length: 100)] private ?string $correo = null; #[ORM\Column(type: Types::DATE_MUTABLE)] private ?\DateTimeInterface $fecha_alta = null; #[ORM\Column(type: Types::DATE_MUTABLE)] private ?\DateTimeInterface $fecha_baja = null; #[ORM\Column] private ?int $id_rol = null; #[ORM\Column] private ?int $orden = null; #[ORM\Column] private ?int $id_partido = null; #[ORM\Column] private ?int $id_eleccion_interna = null; #[ORM\Column] private ?int $id_alianza = null; public function getId(): ?int { return $this->id; } public function getApellidoNombre(): ?string { return $this->apellido_nombre; } public function getDocumento(): ?int { return $this->documento; } public function setDocumento(int $documento): static { $this->documento = $documento; return $this; } public function getSexo(): ?string { return $this->sexo; } public function setSexo(string $sexo): static { $this->sexo = $sexo; return $this; } public function getTipo(): ?string { return $this->tipo; } public function setTipo(string $tipo): static { $this->tipo = $tipo; return $this; } public function getApellido_Nombre(): ?string { return $this->apellido_nombre; } public function setApellido_Nombre(string $apellido_nombre): static { $this->apellido_nombre = $apellido_nombre; return $this; } public function getApellido(): ?string { return $this->apellido; } public function setApellido(string $apellido): static { $this->apellido = $apellido; return $this; } public function getNombre(): ?string { return $this->nombre; } public function setNombre(string $nombre): static { $this->nombre = $nombre; return $this; } public function getDomicilio(): ?string { return $this->domicilio; } public function setDomicilio(string $domicilio): static { $this->domicilio = $domicilio; return $this; } public function getTelefono(): ?string { return $this->telefono; } public function setTelefono(string $telefono): static { $this->telefono = $telefono; return $this; } public function getCorreo(): ?string { return $this->correo; } public function setCorreo(string $correo): static { $this->correo = $correo; return $this; } public function getFechaAlta(): ?\DateTimeInterface { return $this->fecha_alta; } public function setFechaAlta(\DateTimeInterface $fecha_alta): static { $this->fecha_alta = $fecha_alta; return $this; } public function getFechaBaja(): ?\DateTimeInterface { return $this->fecha_baja; } public function setFechaBaja(\DateTimeInterface $fecha_baja): static { $this->fecha_baja = $fecha_baja; return $this; } public function getIdRol(): ?int { return $this->id_rol; } public function setIdRol(int $id_rol): static { $this->id_rol = $id_rol; return $this; } public function getOrden(): ?int { return $this->orden; } public function setOrden(int $orden): static { $this->orden = $orden; return $this; } public function getIdPartido(): ?int { return $this->id_partido; } public function setIdPartido(int $id_partido): static { $this->id_partido = $id_partido; return $this; } public function getIdEleccionInterna(): ?int { return $this->id_eleccion_interna; } public function setIdEleccionInterna(int $id_eleccion_interna): static { $this->id_eleccion_interna = $id_eleccion_interna; return $this; } public function getIdAlianza(): ?int { return $this->id_alianza; } public function setIdAlianza(int $id_alianza): static { $this->id_alianza = $id_alianza; return $this; } } 我试图通过尝试choiceType的不同选项以及尝试entityType来解决问题: ->add('id_autoridad', EntityType::class, [ 'class' => Autoridad::class, 'query_builder' => function (EntityRepository $er) use ($id_partido) { return $er->createQueryBuilder('a') ->andWhere('a.id_partido = :id_partido') ->setParameter('id_partido', $id_partido); }, 'choice_label' => function (Autoridad $autoridad) { if(strlen($autoridad->getApellido_Nombre())> 0){ return $autoridad->getApellido_Nombre(); }elseif(strlen($autoridad->getNombre())> 0){ return $autoridad->getNombre() ." ".$autoridad->getApellido(); }else{ return $autoridad->getId(); } }, 'choice_value' => function (?Autoridad $autoridad) { if ($autoridad !== null) { echo("<script>console.log('idAutoridad: " . $autoridad->getId() ."');</script>"); $value = (int) $autoridad->getId(); return $value; } echo("<script>console.log(' No Entro');</script>"); return ''; }, 'placeholder' => 'Selecciona un estado','required' => true, ]) 您的实体期望 $id_autoridad 为 int,但在形式上您正在使用选择对象的 EntityType

回答 1 投票 0

从异步操作获取数据

在 Symfony 6 中,我需要调用第一个对象(名为 Script),然后这个对象将调用第二个对象(规则),这个规则将调用执行各种操作的最后一个对象(条件)。 ..

回答 1 投票 0

如何在 NelmioApiDoc Bundle 中添加 RequestBody 示例?

我的注释是: * @OA\RequestBody( * 必需=true, * @OA\JsonContent( * @OA\架构( * 类型=“对象”, * @OA\Pro...

回答 2 投票 0

MapRequestPayload 嵌套 DTO

我想使用 MapRequestPayload 将 JSON 请求解析为嵌套的 DTO。目标是验证 DTO 中的数据。 JSON 示例: { “元”:{ “区域设置”:“...

回答 1 投票 0

Symfony 7 MapRequestPayload 嵌套 DTO

我想使用 MapRequestPayload 将 JSON 请求解析为嵌套的 DTO。目标是验证 DTO 中的数据。 JSON 示例: { “元”:{ “区域设置”:“...

回答 1 投票 0

Symfony 表单:所选选项无效

我的symfony应用程序有这个实体: 我的 symfony 应用程序有这个 实体: <?php namespace App\Entity; class Lead { private ?string $zipCode; private ?string $city; public function getZipCode(): ?string { return $this->zipCode; } public function setZipCode(string $zipCode): self { $this->zipCode = $zipCode; return $this; } public function getCity(): ?string { return $this->city; } public function setCity(string $city): self { $this->city = $city; return $this; } } 表格LeadType是: $builder->add('zipCode', TextType::class, [ 'attr' => [ 'placeholder' => 'Ex : 44000', 'onchange' => 'cityChoices(this.value)', ] ]) ->add('city', ChoiceType::class, [ 'choices' => [], 'attr' => ['class' => 'form-control'], 'choice_attr' => function () {return ['style' => 'color: #010101;'];}, ]); 当用户输入邮政编码时,javascript函数cityChoices()使用外部API添加选择选项,例如: 我的问题是控制器中的表单无效。因为用户选择了 LeadType 的选项中未提供的城市('choices' => [])。 这是错误: 0 => Symfony\Component\Form\FormError {#3703 ▼ #messageTemplate: "The selected choice is invalid." #messageParameters: array:1 [▼ "{{ value }}" => "Bar-le-Duc" ] 如何使选择有效? 完全@craight 我添加到表格中: ->addEventListener(FormEvents::PRE_SUBMIT, function(FormEvent$event){ $form = $event->getForm(); $city = $event->getData()['city']; if($city){ $form->add('city', ChoiceType::class, ['choices' => [$city => $city]]); } }) 预提交时,我更新选择并仅让用户选择'choices' => ['Bar-le-Duc' => 'Bar-le-Duc'], 表单在控制器中生效 另一个答案,当将 EntityType 与之前可用但不再可用的实体(例如,软删除或过期)一起使用时,是使用自定义数据转换器在验证之前过滤发布的结果。 请参阅如何使用数据转换器 @ Symfony 文档。 在下面的(非功能性)示例中,EntityType(或ChoiceType)的自定义数据转换器根据给定自定义过滤器的数据库查询结果删除无效值: <?php /** * Transformer for collection of CustomerType objects. * * @implements DataTransformerInterface<Collection<array-key,string>,Collection<array-key,string>> */ class EntityCollectionTransformer implements DataTransformerInterface { protected ?Builder $queryBuilder = null; /** * The valid DeliveryPackOption::id for the current context. * * @var string[] */ protected ?array $validIds = null; /** * Constructor, injects the repository. */ public function __construct( protected readonly EntityRepository $repository ) { } /** * Get the query builder, to apply custom filters. */ public function getQueryBuilder(): Builder { // Reset the query builder $this->queryBuilder = $this->repository->getQueryBuilder(); // Reset the valid ids $this->validIds = null; return $this->queryBuilder; } /** * Get the valid DeliveryPackOption Ids for the current context. * * @return string[] */ public function getValidIds(): array { if (null !== $this->validIds) { return $this->validIds; } if (null === $this->queryBuilder) { $message = sprintf('You must call getQueryBuilder() before calling using %s.', self::class); throw new \LogicException($message); } /** @var Collection<array-key,Entity> */ $results = $this->queryBuilder->getQuery()->execute(); // Get the valid ids from the database $this->validIds = array_map( fn (Entity $option): string => $option->getId(), $results->toArray(), ); return $this->validIds; } /** * Check that the given Entity::id are available as choices for the current context. * * Prevent "invalid" choices to be submitted. * * @param Collection<array-key,string>|null $value * * @return Collection<array-key,string> */ #[\Override] public function transform(mixed $value): Collection { if (!$value instanceof Collection || 0 === $value->count()) { return new ArrayCollection(); } return new ArrayCollection(array_filter( $value->toArray(), fn (string $id): bool => in_array($id, $this->getValidIds(), true) )); } /** * Transform a Entity:id array to its corresponding ArrayCollection of Document. * * @param Collection<array-key,string>|null $value * * @return Collection<array-key,string>|null */ #[\Override] public function reverseTransform(mixed $value): ?Collection { return $value; } } 并在表单中,获取变压器服务,并设置自定义查询过滤器: <?php class FormType extends AbstractType { protected ?EntityTransformer $entityTransformer = null; /** * Set the DeliveryPackOptionReferenceCollectionTransformer service, used for dependency injection. */ #[Required] public function setEntityTransformer( EntityTransformer $entityTransformer ): void { $this->entityTransformer = $entityTransformer; } public function buildForm(FormBuilderInterface $builder, array $options): void { if (!$this->entityTransformer instanceof EntityTransformer) { throw new \RuntimeException('EntityTransformer service is not set.'); } // Prepare the Entity collection filtering transformer query builder $qb = $this->entityTransformer->getQueryBuilder(); $qb->andWhere('deleted = :false'); ->setParameter('false', false); $builder ->add('city', EntityType::class, [ 'class' => Entity::class, ]) ; $builder->get('delivery.deliveryPackOptions') ->addModelTransformer($this->entityTransformer); } }

回答 2 投票 0

允许反斜杠 url symfony2

我正在使用 symfony 2.5 和 Php 5.3.13 制作一个文件资源管理器应用程序。 这里是我的 scanAction 列出了目录的文件: 公共函数listAction($client) { $dir_clients = $this->con...

回答 1 投票 0

具有选择形式的 Symfony DataTransformers

我制作了一个 DataTransformer,它基本上不是针对提交的可用选择。 我的问题是我的变压器收到 ['INFO' => 'INFO', 'WARN' => 'WARN'] 或 ...

回答 1 投票 0

Symfony Turbo 下载 html 文件而不是渲染它

我正在使用 Symfony 7 和 Turbo 制作一个网络应用程序。 我的所有控制器都可以与 Turbo 配合使用,遵循简单的操作 #[路线('/{platform}',名称:'app_platform_pick')] 公共职能

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.