1 回答

TA貢獻(xiàn)1936條經(jīng)驗(yàn) 獲得超7個(gè)贊
我現(xiàn)在可以回答我自己的問題:
解決方案:我只是忘記在 Easyadmin 路由中引用控制器:
# config/routes/easy_admin.yaml
easy_admin_bundle:
resource: 'App\Controller\AdminController'
prefix: /admin
type: annotation
這是針對(duì)有相同問題的每個(gè)人的完整控制器:
// src/Controller/AdminController.php
namespace App\Controller;
use App\Entity\User;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController;
class AdminController extends EasyAdminController
{
private $passwordEncoder;
public function __construct(UserPasswordEncoderInterface $passwordEncoder)
{
$this->passwordEncoder = $passwordEncoder;
}
private function encodeUserPlainPassword($user)
{
$plainPassword = $user->getPlainPassword();
if (!empty($plainPassword)) {
$encoded = $this->passwordEncoder->encodePassword($user, $plainPassword);
$user->setPassword($encoded);
}
}
public function persistEntity($user)
{
$this->encodeUserPlainPassword($user);
parent::persistEntity($user);
}
public function updateEntity($user)
{
$this->encodeUserPlainPassword($user);
parent::updateEntity($user);
}
}
- 1 回答
- 0 關(guān)注
- 117 瀏覽
添加回答
舉報(bào)