0

我将 symfony 版本更改为3.4并面临表单组件的问题 在我使用类似服务的表单之前,首先创建并修改然后创建它。但现在它改变了,create函数等待类名。而且我不知道在这种情况下如何定制。symfony 中的示例3.3我有一个循环,我创建了许多具有特定名称和数据的表单

foreach ($taskExecutions as $i => $execution) {

            $wtf = $this->getChoiceFiledType();
            $wtf->setDataChoice($workTypeObjects);
            $name = 'work_type_object';
            $wtf->setName("{$name}_id_{$i}");
            $wtf->setPlaceHolder($this->getAdditionalFunction()
                ->transLocal('select_default_value', 'common'));
            $renderValue['renderFormWT'] = $this->getFormFactoryInterface()
                ->create(
                    $wtf,
                    null,
                    ['attr' => ['class' => 'work_type_object_id', 'id' => "{$name}_form_{$i}"]]
                )
                ->createView();

 }

我的表格从自定义父母延伸

class ChoiceFiledType extends ExtendsTimeSheetsFilterForm
{
/**
 * @param OptionsResolver $resolver
 */
public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults([
        'required' => false,
        'choices' => $this->getDataChoice(),
        'empty_value' => $this->getPlaceHolder(),
    ]);
}

/**
 * @return string
 */
public function getParent()
{
    return 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
}
}

带有选项的父类:

class ExtendsTimeSheetsFilterForm extends AbstractType
{
/**
 * @var string
 */
private $name = 'timesheets';

/**
 * @var array
 */
private $dataChoice = [];

/**
 * @var string
 */
private $placeHolder = '';

/**
 * @return string
 */
public function getBlockPrefix()
{
    return $this->name;
}

/**
 * @param string $name
 */
public function setName($name)
{
    $this->name = $name;
}

/**
 * @return array
 */
public function getDataChoice()
{
    return $this->dataChoice;
}

/**
 * @param array $dataChoice
 */
public function setDataChoice($dataChoice)
{
    $this->dataChoice = $dataChoice;
}

/**
 * @return string
 */
public function getPlaceHolder()
{
    return $this->placeHolder;
}

/**
 * @param string $placeHolder
 */
public function setPlaceHolder($placeHolder)
{
    $this->placeHolder = $placeHolder;
}
}

在新版本的 symfony 中,我没有机会获得类似服务的形式,然后像这样自定义一些数据

            $wtf = $this->getChoiceFiledType();
            $wtf->setDataChoice($workTypeObjects);
            $name = 'work_type_object';
            $wtf->setName("{$name}_id_{$i}");
            $wtf->setPlaceHolder($this->getAdditionalFunction()
                ->transLocal('select_default_value', 'common'));

只有我能从使用字符串类名创建,但是......之前如何修改数据?示例自定义名称表单或我想要更改机会dataChoiceplaceholder

                $renderValue['renderFormWT'] = $this->getFormFactoryInterface()
                ->create(
                    ChoiceFiledType::class,
                    null,
                    ['attr' => ['class' => 'work_type_object_id', 'id' => "{$name}_form_{$i}"]]
                )
                ->createView();

它在 symfony 3.4 中是如何工作的,或者可能是另一种方式?

4

1 回答 1

0

大多数时候,答案在文档中......

我的服务定义:

app.security_handler:
  class: App\Listener\Security\SecurityHandler

App\Listener\Security\SecurityHandler: '@app.security_handler'

现在security.yaml

form_login:
  login_path: /admin/login
  check_path: /admin/login
  default_target_path: /admin
  username_parameter: login[username_or_email]
  password_parameter: login[password]

  success_handler:    app.security_handler
  failure_handler:    app.security_handler
于 2018-02-28T09:12:31.690 回答