这是错误
参数1传递给 Symfony \ Component \ Security \ Core \ Encoder \ UserPasswordEncoder :: encodePassword() 必须是 Symfony \ Component \ Security \ Core \ User \ UserInterface,实例 给定的App \ Entity \ User,在 C:\ Users \ willi \ Desktop \ Crowdin \ src \ Controller \ CompteController.php在 第44行
CompteController.php:
/**
* @Route("/inscriptions", name="inscription")
*/
public function inscriptions(Request $request, ObjectManager $manager, UserPasswordEncoderInterface $encoder) {
$user = new User();
$form = $this->createForm(RegistrationType::class, $user);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) {
$hash = $encoder->encodePassword($user, $user->getPassword());
$user->setPassword($hash);
$manager->persist($user);
$manager->flush();
return $this->redirectToRoute('login');
}
return $this->render('compte/inscriptions.html.twig', [
'form' => $form->createView()
]);
}
User.php:
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @UniqueEntity(
* fields={"email"},
* message="L'email que vous avez indiqué est déja utilisé !"
* )
*/
class User implements UserInterface
{
答案 0 :(得分:2)
听起来您只是将接口导入到本地名称空间中,而没有实际实现它。
namespace foo; // namespace declaration
use Bar\UserInterface; // namespace import, does not actually implement it.
class User implements UserInterface { // <- this is the important part
// now you need to implement the methods specified in the interface.
}
或者,假设类Bar\User
实现了Bar\UserInterface
:
class User extends Bar\User {
// now you only need to define/redefine the specific things that you want to
}