如何解决重命名 SonataUserUser 实体后,无法为命名路由“admin_app_sonatauseruser_create”生成 URL
我的应用程序运行良好,直到我决定将 SonataUserUser 重命名为 User 并将 SonataUserUserGroup 重命名为 group。
这就是我的用户实体的样子
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Sonata\UserBundle\Entity\BaseUser;
/**
* @ORM\Entity
* @ORM\Table(name="users")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;
.....
public function __construct()
{
parent::__construct();
}
public function __toString()
{
return $this->getFirstName() === null ? 'New' : $this->getFullname();
}
}
declare(strict_types=1);
namespace App\Admin;
use FOS\UserBundle\Model\UserManagerInterface;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelType;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\Form\Type\DatePickerType;
use Sonata\UserBundle\Form\Type\SecurityRolesType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\LocaleType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Sonata\UserBundle\Admin\Model\UserAdmin as BaseUserAdmin;
class UserAdmin extends BaseUserAdmin
{
protected $translationDomain = 'SonataBundle';
/**
* {@inheritdoc}
*/
protected function configureShowFields(ShowMapper $showMapper): void
{
$showMapper
->with('General')
->add('username')
->add('email')
->end()
->with('Groups')
->add('groups')
->end()
->with('Profile')
->add('dateOfBirth')
->add('firstname')
->add('lastname')
->add('website')
->add('biography')
->add('gender')
->add('locale')
->add('timezone')
->add('phone')
->end()
;
}
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper): void
{
// define group zoning
$formMapper
->tab('Details')
->with('Profile',['class' => 'col-md-6'])->end()
->with('General',['class' => 'col-md-6'])->end()
->with('Social',['class' => 'col-md-6'])->end()
->end();
$Now = new \DateTime();
$genderOptions = [
'choices' => \call_user_func([$this->getUserManager()->getClass(),'getGenderList']),'required' => true,'translation_domain' => $this->getTranslationDomain(),];
$formMapper
->tab('Details')
->with('General')
->add('username')
->add('email')
->add('plainPassword',PasswordType::class,[
'required' => (!$this->getSubject() || null === $this->getSubject()->getId()),'label' => 'Password','help' => 'Updating this field will change your password.'
])
->end()
->with('Profile')
->add('firstname',null,['required' => false])
->add('lastname',['required' => false])
->add('dateOfBirth',DatePickerType::class,[
'required' => false,])
->add('gender',ChoiceType::class,$genderOptions)
->add('locale',LocaleType::class,['required' => false])
->add('timezone',TimezoneType::class,['required' => false])
->add('phone',['required' => false])
->end()
->end();
}
}
config/routes/sonata_admin.yaml
admin_area:
resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
prefix: /admin
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
config/packages/sonata_user
sonata_user:
security_acl: false
manager_type: orm
class:
user: App\Entity\User
group: App\Entity\Group
mailer: sonata.user.mailer.default
impersonating:
route: sonata_admin_dashboard
table:
user_group: "users_groups"
我得到的错误是 An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "admin_app_sonatausergroup_create" as such route does not exist.").
中的 in vendor/sonata-project/admin-bundle/src/Resources/views/Block/block_admin_list.html.twig (line 28)
。
我很感激任何形式的帮助
解决方法
php bin/console debug:router
返回什么?您可以找到我期望的正在使用的路线名称。我正在开发的示例输出:
dashboard ANY ANY ANY /account/dashboard
home ANY ANY ANY /
app_register ANY ANY ANY /register
app_login ANY ANY ANY /login
app_logout ANY ANY ANY /logout
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。