symfony-forms 相关问题

Symfony表单组件是一个独立的库,可以在Symfony项目之外使用。

Symfony2 数据转换器、验证器和错误消息

我问了这个问题,发现我们无法获取DataTransformer抛出的错误消息(根据唯一回答的用户的说法,也许有可能,我不知道)。 无论如何,现在我...

回答 1 投票 0

如何获取登录用户的ID?我使用 symfony 7 [重复]

我想获取登录用户的用户ID,以便它与数据库中的评论链接,因为它们具有一对一的关系 ReviewFormType 类扩展 AbstractType { 公共乐趣...

回答 1 投票 0

如何获取 Symfony 嵌入式动态表单未映射数据

我有一个动态生成的动态表单,如下所示。 我有一个动态生成的动态表单,如下所示。 <input type="hidden" id="project_teams_18_cropped_file_key" name="project[teams][1][cropped_file_key]" class="cropped_file_key"> <input type="hidden" id="project_teams_18_cropped_file_key" name="project[teams][2][cropped_file_key]" class="cropped_file_key"> <input type="hidden" id="project_teams_18_cropped_file_key" name="project[teams][8][cropped_file_key]" class="cropped_file_key"> ..... <input type="hidden" id="project_teams_18_cropped_file_key" name="project[teams][dynamic_key][cropped_file_key]" class="cropped_file_key"> 表格类型: ->add('cropped_file_key', HiddenType::class, [ 'mapped' => false ]) 由于表单输入键是随机顺序的,我不能这样做 foreach($project->getTeams() as $key => $value){} 因为 $key 按顺序运行。 我尝试了$form->get('cropped_file_key'),但没有成功,它要求提供钥匙。 获取此类动态表单输入值的最佳方法是什么? 您的 FormType 是您的父表单还是 CollectionType 类型的子表单? 如果它是子表单,如本文访问嵌入式表单数据中所述,您可以尝试以下操作: foreach ($project->getTeams() as $key => $coordinator) { $coordinatorImage = $teamImageUpload->uploadTeamImage( $form->get('teams')[$key]['cropped_file']->getData(), $coordinator ); $coordinator->setImage($coordinatorImage); } 这将允许您浏览您的收藏并查看它们包含的内容`。 否则,您应该考虑使用 Symfony 文档中的嵌入式表单集合。

回答 1 投票 0

Symfony 7 动态修改表单

我只是无法让它工作:-( 我现在有一个 FormType 作为示例,其中我有一个带有选项 1 和选项 2 的 Select Fierlt 现在我只是想要,当我选择选项 2 时,构建器添加一个新的

回答 1 投票 0

如何将 EntityType 字段设置为只读/禁用,以便该值无法编辑但仍与表单一起发送?

在Symfony 6中,当我渲染设置只读属性的EntityType(HTML选择字段)时,该字段实际上被修改了。 如果我设置为禁用,那么我会收到错误,因为此字段是必需的。 我怎样才能...

回答 1 投票 0

在表单事件中访问未映射的表单数据

我想创建一个依赖选择框:如果选择第一个选择框,则应填充第二个选择框。 我的第一个选择框未映射到模型。我在我的

回答 2 投票 0

Symfony 7 带有附加参数的 CollectionType

多年后我又回到了 Symfony,我很喜欢这个新版本 7。 我正在与 CollectionType 作斗争,因为我只需要显示基于主对象的某些字段,但我找不到...

回答 1 投票 0

Symfony 3 - 提交和验证后修改表单值

在我的应用程序中,我需要修改提交并验证的表单值。 该用例是一个带有地址的表单,该地址已由外部 Web 服务验证并可能更正。我

回答 1 投票 0

如何验证 Symfony 表单中的日期,以便用户无法选择当前日期之后的任何日期

我有一个面板来获取一些交易,用户可以选择月份和年份并获取该月份和年份的交易。问题是,如果您错误地选择了未来的日期,我会...

回答 1 投票 0

是否可以使用只读类作为 symfony 表单的 DTO?

我有一个简单的 symfony 表单用于创建 ThingEntity。 我有一个 CreateThingType 和一个 CreateThing DTO: 数据传输组织 命名空间App\DataTransfer; 使用App\Validator\UniqueNameForParent; 使用 Symfony\

回答 1 投票 0

为什么我会收到错误:“在属性路径“名称”处给出了类型为“string”的预期参数,“null””?

我正在 Symfony 6.4 中使用 Doctrine ORM 对记录进行简单的更新。我使用名为 Category 的实体进行此注册表更新,它看起来像(有些内容是西班牙语): 命名空间 App\Entity...

回答 1 投票 0

Symfony 6,提交表单后未发布表单文本区域

我有简单的联系表: 我有简单的联系表: <form id='contactform' action="{{ path('app_contact_send') }}" method="POST" name="contactform"> <ul class="form-cover"> <li class="inp-name"> <label>Nombre * (requerido)</label> <input id="name" type="text" name="your-name"> </li> <li class="inp-text"> <label>Mensaje * (requerido)</label> <textarea id="mess" name="mess"></textarea> </li> <li class="inp-email"> <label>E-mail * (requerido)</label> <input id="email" type="email" name="your-email"> </li> </ul> <div class="btn-form-cover"> <button id="#submit" type="submit" class="btn">enviar</button> </div> </form> 单击提交按钮后,我有一个控制器从以下位置收集数据: $name = $request->request->get('name'); $from = $request->request->get('email'); $mess = $request->request->get('mess'); 然后使用该数据在控制器中的 POST 方法中通过 symfony mailer 发送电子邮件: $email = (new Email()) ->from($from) ->replyTo($from) ->to('[email protected]') ->cc('[email protected]') ->bcc('[email protected]') ->replyTo($from) ->subject('Mensaje desde www.website.com') ->text(sprintf('Mensaje enviado: %s, por: %s.', $mess, $name)); 电子邮件已发送,但从文本区域收集的变量“混乱”始终为空,名称和电子邮件具有值。 对于文本区域类型字段我还需要做些什么吗? 请求由 Symfony UX Turbo 管理。 变量混乱应该有一个值。 我确实追踪到了一个 js 文件,其中捕获了鼠标单击,并将表单值发布到数组中。 修改此项以匹配表单上的字段。 这样就解决了问题。

回答 1 投票 0

如何展平嵌套表单的渲染

在我的用例中,我使用 Symfony 表单系统主要用于渲染设施。我不使用表单系统设施来处理由其他部分处理的表单发送的请求数据...

回答 1 投票 0

如何构建和重用 Symfony 表单?

我正在使用 Symfony 6.4,我不确定如何分解表单中的代码。 这是一个具体的例子: 在 UserRegistrationType 中,我这样做: 公共函数 buildForm(FormBuilderInterface $builder, ar...

回答 1 投票 0

Symfony 6 - 表单的最佳实践

我正在使用 Symfony 6.4,我不确定如何分解表单中的代码。 这是一个具体的例子: 在 UserRegistrationType 中,我这样做: 公共函数 buildForm(FormBuilderInterface $builder, ar...

回答 1 投票 0

是否可以用通用表单进行表单收集?交响乐

所以我正在做一些练习,所以我有一个巨大的表格(10 个练习)和一系列较小的表格(小练习)。我的问题是练习可以是任何东西,也可以是一个

回答 1 投票 0

当我使用大于、小于或等于过滤器时,出现 count() 错误

在书籍页面上,我添加了按书籍作者数量的过滤器,我可以在其中指定 (=n | >n | 在书籍页面上,我添加了按书籍作者数量的过滤器,我可以在其中指定 (=n | >n | public function findPaginated(InterpretationTranslationSourceFilter $filter): NewPaginator { $qb = $this->createQueryBuilder('s') ->leftJoin('s.authorToSourceRelations', 'atsr') ->select('s as interpretationTranslationSource') ->addSelect('COUNT(DISTINCT atsr.id) AS authorToSourceRelationsCount') ->groupBy('s.id'); if ($filter->isHasLink() OR $filter->getDontHasLink()) { if ($filter->isHasLink()) { $qb->andWhere('s.url IS NOT NULL'); } if ($filter->getDontHasLink()) { $qb->andWhere('s.url IS NULL'); } } if ($filter->getSortByAuthorsCount()) { $comparisonOperator = substr($filter->getSortByAuthorsCount(), 0, 1); $authorsCount = (int) substr($filter->getSortByAuthorsCount(), 1); switch ($comparisonOperator) { case '=': $qb->having('authorToSourceRelationsCount = :authorsCount') ->setParameter('authorsCount', $authorsCount); break; case '>': $qb->having('authorToSourceRelationsCount > :authorsCount') ->setParameter('authorsCount', $authorsCount); break; case '<': $qb->having('authorToSourceRelationsCount < :authorsCount') ->setParameter('authorsCount', $authorsCount); break; default: $qb->orderBy('s.title', 'ASC'); break; } } if ($filter->getTitle()) { $qb->andWhere('s.title like :title') ->setParameter('title', '%' . $filter->getTitle() . '%'); } if ($filter->getUrl()) { $qb->andWhere('s.url LIKE :url') ->setParameter('url', '%' . $filter->getUrl() . '%'); } return new NewPaginator($qb, $filter); } 当我指定任何值时,我收到错误: count():参数#1($value)必须是 Countable|array 类型,Doctrine\ORM\Query\Expr\Andx 给定 我试图补充我的查询,重建它们,但一切都是徒劳的 直接在条件中将 HAVING 子句更改为 COUNT(DISTINCT atsr.id)。这应该可以解决问题。 HAVING 子句应该对聚合函数的结果进行操作,在本例中,它是不同作者 ID 的计数。 switch ($comparisonOperator) { case '=': $qb->having('COUNT(DISTINCT atsr.id) = :authorsCount') ->setParameter('authorsCount', $authorsCount); break; case '>': $qb->having('COUNT(DISTINCT atsr.id) > :authorsCount') ->setParameter('authorsCount', $authorsCount); break; case '<': $qb->having('COUNT(DISTINCT atsr.id) < :authorsCount') ->setParameter('authorsCount', $authorsCount); break; default: $qb->orderBy('s.title', 'ASC'); break; } 如果仍有问题,请尝试将 having 替换为 andHaving

回答 1 投票 0

Symfony 6 验证器不适用于电话号码

所以我在电话号码验证方面遇到一些问题。 我的错误是: 当我尝试输入非数字的内容时,就会发生这种情况。我需要阻止这种情况。 我已经尝试了很多方法,但是在

回答 1 投票 0

SQLSTATE[42S22]:未找到列:1054“where 子句”sonata symfony 中的未知列“t0.id”

我有两个实体,Entity Devisvente 扩展奏鸣曲管理包中的实体 Ventes, 这是我的实体 Ventes : 我有两个实体,奏鸣曲管理包中的实体Devisvente扩展实体Ventes, 这是我的实体Ventes: <?php namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Ventes * * @ORM\Table(name="ventes") * @ORM\Entity(repositoryClass="AppBundle\Repository\VentesRepository") */ class Ventes { /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="reference", type="string", length=255) */ private $reference; /** * @var \DateTime * * @ORM\Column(name="date", type="datetime") */ private $date; #........... #........... } 这是我的实体Devisvente扩展Ventes表: <?php namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Devisvente * * @ORM\Table(name="ventes") * @ORM\Entity(repositoryClass="AppBundle\Repository\VentesRepository") */ class Devisvente extends Ventes { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; } 每个类都有一个管理类(例如:实体 Ventes 有一个 VentesAdmin.php) 这是我对实体的班级管理员 Ventes : <?php namespace AppBundle\Admin; use Sonata\AdminBundle\Admin\AbstractAdmin; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Show\ShowMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Form\FormMapper; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; class VentesAdmin extends AbstractAdmin { protected function configureFormFields(FormMapper $formMapper) { $formMapper ->with('Facture', array('class' => 'col-md-6')) ->add('compte', 'entity', array( 'class' => 'AppBundle\Entity\compte', 'choice_label' => 'raison_sociale', 'required' => false )) ->add('objet', 'text') ->add('type', ChoiceType::class, array( 'choices' => array( 'Facture' => 'Facture partie ventes', ))) ->add('reference', 'text') ->add('date', 'sonata_type_date_picker') ->end() ->with('Autres Informations', array('class' => 'col-md-6')) ->add('User', 'entity', array( 'class' => 'AppBundle\Entity\User', 'choice_label' => 'username', 'required' => false )) ->add('commission', 'text') ->add('validite_du_devis', 'number') ->add('mode_de_paiement', 'text') ->add('compte_bancaire', 'text') ->end() ->with('Acticles', array('class' => 'col-md-12')) ->add('articles', 'sonata_type_model', array( 'class' => 'AppBundle\Entity\Article', 'property' => 'reference', 'multiple' => true )) ->end() ->with('Packs', array('class' => 'col-md-12')) ->add('packs', 'sonata_type_model', array( 'class' => 'AppBundle\Entity\packs', 'property' => 'reference', 'multiple' => true )) ->end() ; } #...... protected function configureListFields(ListMapper $listMapper) { $listMapper ->addIdentifier('reference') ->add('compte.raison_sociale') ->add('date') ->add('_action', 'actions', array( 'actions' => array( 'show' => array(), 'edit' => array(), 'delete' => array(), ))) ; } } 这是我的实体班级管理员Devisvente: <?php namespace AppBundle\Admin; use Sonata\AdminBundle\Admin\AbstractAdmin; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Show\ShowMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Form\FormMapper; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; class DevisventeAdmin extends AbstractAdmin { #...... #...... protected function configureFormFields(FormMapper $formMapper) { $formMapper ->with('Facture', array('class' => 'col-md-6')) ->add('compte', 'entity', array( 'class' => 'AppBundle\Entity\compte', 'choice_label' => 'raison_sociale', 'required' => false )) ->add('objet', 'text') ->add('type', ChoiceType::class, array( 'choices' => array( 'Facture' => 'Facture partie ventes', ))) ->add('reference', 'text') ->add('date', 'sonata_type_date_picker') ->end() ->with('Autres Informations', array('class' => 'col-md-6')) ->add('User', 'entity', array( 'class' => 'AppBundle\Entity\User', 'choice_label' => 'username', 'required' => false )) ->add('commission', 'text') ->add('validite_du_devis', 'number') ->add('mode_de_paiement', 'text') ->add('compte_bancaire', 'text') ->end() ->with('Acticles', array('class' => 'col-md-12')) ->add('articles', 'sonata_type_model', array( 'class' => 'AppBundle\Entity\Article', 'property' => 'reference', 'multiple' => true )) ->end() ->with('Packs', array('class' => 'col-md-12')) ->add('packs', 'sonata_type_model', array( 'class' => 'AppBundle\Entity\packs', 'property' => 'reference', 'multiple' => true )) ->end() ; } #...... #...... protected function configureListFields(ListMapper $listMapper) { $listMapper ->addIdentifier('reference') ->add('compte.raison_sociale') ->add('date') ->add('_action', 'actions', array( 'actions' => array( 'show' => array(), 'edit' => array(), 'delete' => array(), ))) ; } } 当我想显示、编辑或删除 Devisventes 列表中的 listField 中的项目时: 结果,我遇到了这个问题: 你能帮我吗??? 这是我的services.yml # Learn more about services, parameters and containers at # http://symfony.com/doc/current/service_container.html parameters: #parameter_name: value services: #service_name: # class: AppBundle\Directory\ClassName # arguments: ['@another_service_name', 'plain_value', '%parameter_name%'] admin.facture: class: AppBundle\Admin\VentesAdmin arguments: [~, AppBundle\Entity\Ventes, ~] tags: - { name: sonata.admin, manager_type: orm, group: Ventes, label: Facture, icon: "<i class=\"fa fa-file-text\"></i>" } admin.devisvente: class: AppBundle\Admin\DevisventeAdmin arguments: [~, AppBundle\Entity\Devisvente, ~] tags: - { name: sonata.admin, manager_type: orm, group: Ventes, label: Devis } admin.user: class: AppBundle\Admin\UserAdmin arguments: [~, AppBundle\Entity\User, ~] tags: - { name: sonata.admin, manager_type: orm, group: Settings, label: Users, icon: "<i class=\"fa fa-cog\"></i>" } 你能帮我吗? 我认为您应该删除 $id 实体中的 DevisVente。 我认为问题与注释有关。 父类和子类的注解指向同一个表。我认为如果父类没有映射到数据库,你必须删除它的注释 /** * Ventes * * * */ class Ventes { ... } 属性也应该声明为受保护的,而不是私有的以便继承 /** * Ventes * * */ class Ventes { ... protected $id; ... protected $reference; ... protected $date; } 我也遇到了同样的问题。为了解决这个问题,我使用了学说继承映射注释: 参见继承映射 因此,您可以将数据存储在单个表中或设置类表继承。 此外,无需重写派生类中的 id 属性。 作为替代解决方案,可以使用 @MappedSuperclass 注释创建抽象父类,因此可以将数据存储在单独的表中。 如果其他人遇到同样的问题,我也会遇到同样的错误,但这是由于我的学说 xml 模型中的小写实体名称所致。

回答 4 投票 0

如何翻译 Symfony 3 形式?

翻译树枝模板中的内容似乎简单明了:我运行 bin/console Translation:update 来填充翻译文件。问题在于它似乎忽略了形式。 创建后

回答 3 投票 0

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