Symfony-ux-live-comment Не найдено соответствующего свойства «form» или аргумента mount()Php

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Symfony-ux-live-comment Не найдено соответствующего свойства «form» или аргумента mount()

Сообщение Anonymous »


class PostForm extends AbstractController
{
use DefaultActionTrait;
use ComponentWithFormTrait;

/**
* The initial data used to create the form.
*/
#[LiveProp]
public ?Post $initialFormData = null;

protected function instantiateForm(): FormInterface
{
// we can extend AbstractController to get the normal shortcuts
return $this->createForm(PostType::class, $this->initialFormData);
}

#[LiveAction]
public function save(EntityManagerInterface $entityManager)
{
// Submit the form! If validation fails, an exception is thrown
// and the component is automatically re-rendered with the errors
$this->submitForm();

/** @var Post $post */
$post = $this->getForm()->getData();
$entityManager->persist($post);
$entityManager->flush();

$this->addFlash('success', 'Post saved!');

return $this->redirectToRoute('app_post_show', [
'id' => $post->getId(),
]);
}
}

class Post
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;

#[ORM\Column(length: 255)]
private ?string $title = null;

#[ORM\Column(length: 255)]
private ?string $slug = null;

#[ORM\Column(type: Types::TEXT)]
private ?string $content = null;

..........

}

class PostType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('title')
->add('slug')
->add('content')
;
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Post::class,
]);
}
}

class PostController extends AbstractController
{
#[Route('/post', name: 'app_post')]
public function index(): Response
{
return $this->render('post/index.html.twig', [
'controller_name' => 'PostController',
'form' => $this->createForm(PostType::class, new Post())
]);
}

#[Route('/admin/post/{id}/edit', name: 'app_post_edit')]
public function edit(Request $request, Post $post, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(PostType::class, $post);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
// save, redirect, etc
}

return $this->render('post/edit.html.twig', [
'post' => $post,
'form' => $form->createView(), // use $form->createView() in Symfony

Подробнее здесь: https://stackoverflow.com/questions/789 ... ent-was-fo
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»