В Symfony 5 (да и вообще в Symfony) полный новичок. Помогите, пожалуйста, отловить ошибку. Уже неделю бьюсь...
Контроллер:
/* /src/Controller/UserAdminController.php */
<?php
namespace App\Controller;
use App\Entity\Users;
use App\Form\UsersEditAdminType;
//use http\Env\Request;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\User\User;
use Symfony\Component\HttpFoundation\Request;
class UsersAdminController extends AbstractController
{
/**
* @Route("/admin/users", name="admin_users")
*/
public function users_list()
{
return $this->render('users_admin/index.html.twig', [
'controller_name' => 'UsersAdminController',
]);
}
/**
* @Route("/admin/users/add", name="admin_users_add")
*/
public function users_add(Request $request, EntityManagerInterface $manager, UserPasswordEncoderInterface $passwordEncoder)
{
$users = new Users();
$form = $this->createForm(UsersEditAdminType::class, $users);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$password = $passwordEncoder->encodePassword($user, $user->getPlainPassword());
$user->setPassword($password);
$em = $this->getDoctrine()->getManager();
$em->persist($users);
$em->flush();
return $this->redirectToRoute('admin_users');
}
return $this->render('users_edit_admin/index.html.twig', [
'controller_name' => 'UsersAdminController',
]);
}
/**
* @Route("/admin/users/edit/{user_id}", name="admin_users_edit")
*/
public function users_edit()
{
return $this->render('users_edit_admin/index.html.twig', [
'controller_name' => 'UsersAdminController',
]);
}
}
Сущность:
/* /src/Entity/Users.php */
<?php
namespace App\Entity;
use App\Repository\UsersRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UsersRepository::class)
*/
class Users implements UserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $username;
/**
* @ORM\Column(type="string", length=255)
*/
private $password;
private $passwordPlain;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $usergroup = [];
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $user_status;
/**
* @ORM\Column(type="string", length=255)
*/
private $email;
public function getId(): ?int
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getPasswordPlain(): ?string
{
return $this->passwordPlain;
}
public function setPasswordPlain(string $passwordPlain): self
{
$this->passwordPlain = $passwordPlain;
return $this;
}
public function getUsergroup(): ?array
{
return $this->usergroup;
}
public function setUsergroup(?array $usergroup): self
{
$this->usergroup = $usergroup;
return $this;
}
public function getUserStatus(): ?int
{
return $this->user_status;
}
public function setUserStatus(?int $user_status): self
{
$this->user_status = $user_status;
return $this;
}
public function getRoles()
{
// TODO: Implement getRoles() method.
}
public function getSalt()
{
// TODO: Implement getSalt() method.
}
public function eraseCredentials()
{
$this->passwordPlain = null;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
}
Форма:
/* /src/Form/UserEditAdminType.php */
<?php
namespace App\Form;
use App\Entity\Users;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class UsersEditAdminType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('username')
->add('passwordPlain', RepeatedType::class, [
'type' => PasswordType::class
])
->add('usergroup', ChoiceType::class, array(
'multiple' => true,
'choices' => array(
'Супер Администратор' => 1,
'Администратор' => 2,
'Пользователь' => 3,
),
))
->add('email', EmailType::class)
->add('user_status')
;
/* $builder->get('usergroup')
->addModelTransformer(new CallbackTransformer(
function ($usergroupArray) {
// transform the array to a string
return count($usergroupArray)? $usergroupArray[0]: null;
},
function ($usergroupString) {
// transform the string back to an array
return [$usergroupString];
}
)); */
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Users::class,
]);
// $resolver->setDefaults([]);
}
}
Шаблон:
/* /templates/user_edit_admin/index.html.twig */
{% extends 'base.html.twig' %}
{% block title %}Управление пользователями{% endblock %}
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
<div class="example-wrapper">
<h1>Управление пользователями</h1>
{{ form_start() }}
{{ form_widget() }}
<button type="submit">Сохранить</button>
{{ form_end() }}
</div>
{% endblock %}
Таблица в БД (используется Postgres):
CREATE TABLE public."user" (
id integer NOT NULL,
email character varying(255) NOT NULL,
password character varying(255) NOT NULL,
usergroup integer NOT NULL,
user_status integer NOT NULL,
roles json NOT NULL,
confirmation_code character varying(20) DEFAULT NULL::character varying,
is_confirmed boolean NOT NULL
);
Встроенный в Symfony дебаггер показывает ошибку "Too few arguments to function Symfony\Component\Form\FormRenderer::renderBlock(), 0 passed in /var/www/html/iv/var/cache/dev/twig/b4/b4b4a90f30f2f219c62c85d967bfb0992520ed5566daf4c59152d9027c9fb47a.php on line 97 and at least 2 expected", подсвечивая в файле UsersAdminController.php вторую строку следующего кода:
return $this->render('users_edit_admin/index.html.twig', [
'controller_name' => 'UsersAdminController',
]);
С Symfony только знакомлюсь, нигде в интернете не могу найти что я делаю не так. Помогите, пожалуйста...