M
M
Marellz2019-04-05 19:52:56
symfony
Marellz, 2019-04-05 19:52:56

Whether it is admissible to use pieces of View in Controller?

Good afternoon!
When studying Symphony, the following question arose: is it permissible to operate the display in the controller?
For example, in Symfony Forms , when creating a form, not only logic is written in it, but also its display:

$form = $this->createFormBuilder($task)
        ->add('task', TextType::class)
        ->add('dueDate', DateType::class)
        ->add('save', SubmitType::class, ['label' => 'Create Task']) // - лейбл - это уже часть шаблона, верно?
        ->getForm();

Moreover, the form itself allows you to redefine html attributes in the code, which, logically, should not appear in the controller, only in the view (code directly from the documentation ):
$builder->add('body', TextareaType::class, [
    'attr' => ['class' => 'tinymce'],
]);

To what extent is this acceptable in terms of code purity? Is it possible (and should) it be bypassed somehow?
For example, in the controller, setting only the processing logic and data structure (model), and already in the template, pass parameters for display, something like
<?php $form->render( [
     'field' => [
        'class' => 'tinymce', 
        'label' => 'Лейбл для поля',
        ...
    ], ...
] ); ?>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question