Symfony 3表单:在PRE_SUBMIT事件侦听器上添加新字段+数据

时间:2016-12-05 11:17:45

标签: symfony

我尝试添加字段并使用事件侦听器为其提供数据。新数据的值取决于相同表单中其他提交字段的数据,因此我使用Symfony 2。我没有在class TaskType extends AbstractType { /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name') ->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { $form = $event->getForm(); $form->add('country', null, array('data' => 'españa')); }); } 上尝试,所以我也不知道结果是否也一样。

Task

问题:新数据(国家/地区)永远不会保留。我做错了什么?

这里有class Task { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(type="string", length=255, name="name", nullable=true) */ protected $name; /** * @ORM\Column(type="string", length=255, name="country", nullable=true) */ protected $country; public function __toString() { return $this->name; } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set name * * @param string $country * * @return Manufacturer */ public function setCountry($country) { $this->country = $country; return $this; } /** * Get country * * @return string */ public function getCountry() { return $this->country; } /** * Set name * * @param string $name * * @return Manufacturer */ public function setName($name) { $this->name = $name; return $this; } /** * Get name * * @return string */ public function getName() { return $this->name; } } 实体:

using System;

namespace Calculator
{
class Program
{
    public static void Main(string[] args)

    { 

    public int number01;
    public int number02;
    public int Number03

    {
        get

        {
            return number02 / number01;
        }
    }

    class Program1 : Program
    {

        public int DivideFinal()
        {

            Console.Write("Enter a number to be divided: ");
            Console.ReadKey();
            number01 = Convert.ToInt32(Console.ReadKey());
            Console.WriteLine("Enter another number to be divided");
            number02 = Convert.ToInt32(Console.ReadKey());
            Console.WriteLine("The result is: " + Number03);
            Console.ReadKey();
        } 

0 个答案:

没有答案