Я пытаюсь закодировать пароль, который я пропускаю через сообщение, но он выдает ошибку при объявлении аргумента в функции.
Не удалось разрешить аргумент $ encoder для "App \" Controller \ UsuarioController :: altapropietario () ", может быть, вы забыли зарегистрировать контроллер в качестве службы или пропустили пометку его« controller.service_arguments »? *
Здесь я вставляю всю функцию, это имеет форму и просто для регистрации новых пользователей.
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class UsuarioController extends AbstractController
{
public function altaPropietario(Request $request, UserPasswordEncoderInterface $encoder )
{
$propietario = new Usuario();
$form = $this->createForm(AltaPropietarioType::class, $propietario);
$form->handleRequest($request);
if ($form->isSubmitted())
{
$propietario->setRole("ROLE_PROP");
$encoded = $encoder->encodePassword($propietario, $propietario->getPassword());
$propietario->setPassword($encoded);
// rest of the implementation not included.
}
}
}
Мой код безопасности:
security:
encoders:
App\Entity\Usuario: bcrypt
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
users_in_memory: { memory: null }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: lazy
provider: users_in_memory
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#firewalls-authentication
# https://symfony.com/doc/current/security/impersonating_user.html
# switch_user: true
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
services.yaml:
parameters:
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones