12

我在本地安装了新的 Symfony 5 项目,并添加了 Easy Admin trought Symfony CLI:

symfony composer req admin

我应该有/admin路线,但它不见了

我跑:

symfony console cache:clear

symfony composer dump-autoload

rm -rf var/cache/*

symfony console debug:router
 -------------------------- -------- -------- ------ ----------------------------------- 
  Name                       Method   Scheme   Host   Path                               
 -------------------------- -------- -------- ------ ----------------------------------- 
  _preview_error             ANY      ANY      ANY    /_error/{code}.{_format}           
  _wdt                       ANY      ANY      ANY    /_wdt/{token}                      
  _profiler_home             ANY      ANY      ANY    /_profiler/                        
  _profiler_search           ANY      ANY      ANY    /_profiler/search                  
  _profiler_search_bar       ANY      ANY      ANY    /_profiler/search_bar              
  _profiler_phpinfo          ANY      ANY      ANY    /_profiler/phpinfo                 
  _profiler_search_results   ANY      ANY      ANY    /_profiler/{token}/search/results  
  _profiler_open_file        ANY      ANY      ANY    /_profiler/open                    
  _profiler                  ANY      ANY      ANY    /_profiler/{token}                 
  _profiler_router           ANY      ANY      ANY    /_profiler/{token}/router          
  _profiler_exception        ANY      ANY      ANY    /_profiler/{token}/exception       
  _profiler_exception_css    ANY      ANY      ANY    /_profiler/{token}/exception.css   
  homepage                   ANY      ANY      ANY    /                                  
 -------------------------- -------- -------- ------ ----------------------------------- 
// config/routes/easy_admin.yaml

easy_admin_bundle:
    resource: '@EasyAdminBundle/Controller/EasyAdminController.php'
    prefix: /admin
    type: annotation
symfony console router:match /admin

                                                                                                                       
 [ERROR] None of the routes match the path "/admin"

我错过了什么?

4

10 回答 10

13

您需要创建至少一个仪表板。尝试:

php bin/console make:admin:dashboard

接下来,您可以使用以下命令创建 CrudController:

php bin/console make:admin:crud

https://symfony.com/doc/master/bundles/EasyAdminBundle/dashboards.html

于 2020-06-21T17:08:33.887 回答
5

是的,我现在正在读这本书,遇到了同样的问题。

首先,确保您的工作目录是干净的(运行“ git status ”并删除由 EasyAdminBundle 设置所做的所有更改)。

然后运行:

composer require easycorp/easyadmin-bundle:2.*

安装 EasyAdminBundle 版本 2;使用此版本,您可以按照书中的说明进行操作。

于 2020-06-27T11:31:53.977 回答
3

EasyAdminBundle v3 有另一个配置,您不再需要使用EasyAdminController资源。

您可以在此处找到有关它的更多信息

https://github.com/EasyCorp/EasyAdminBundle/blob/master/src/Controller/EasyAdminController.php

和这里

https://symfony.com/doc/master/bundles/EasyAdminBundle/dashboards.html

于 2020-06-20T13:41:14.293 回答
3

从 easyadmin 2 迁移到 3 时,似乎没有保留路由名称。一种方法是在 DashboardController 中添加

/**
 * @Route("/admin", name="easyadmin")
 */
public function index(): Response
{
    return parent::index();
}
于 2020-08-19T14:28:33.137 回答
3

我解决了这个问题如下:

  1. 删除 EasyAdmin 3
composer remove admin
  1. 安装附加包。
composer require "easycorp/easyadmin-bundle":"^2.3"
  1. 更新软件包。
composer update
于 2020-09-16T12:20:34.900 回答
3

正如其他人已经说过的,您需要创建一个仪表板:

php bin/console make:admin:dashboard

然后创建至少一个 crud 控制器。由于您似乎使用的是 Fast Track 书,因此您需要键入以下命令两次,并为评论和会议创建一个:

php bin/console make:admin:crud

我也在使用 Fast Track 书,这就是我的文件的最终结果。我仍在学习easy admin3,因此没有声称最佳实践,但这应该使菜单看起来像在Fast Track屏幕截图中一样:

src/Controller/Admin/DashboardController.php:

/**
 * @Route("/admin", name="admin")
 */
public function index(): Response
{
    $routeBuilder = $this->get(CrudUrlGenerator::class)->build();

    return $this->redirect($routeBuilder->setController(ConferenceCrudController::class)->generateUrl());
}

public function configureDashboard(): Dashboard
{
    return Dashboard::new()
        ->setTitle('Guestbook');
}

public function configureMenuItems(): iterable
{
    yield MenuItem::linktoRoute('Back to website', 'fa fa-home', 'homepage');
    yield MenuItem::linkToCrud('Conference', 'fa fa-map-marker', Conference::class);
    yield MenuItem::linkToCrud('Comment', 'fa fa-comment', Comment::class);
}

src/Controller/Admin/CommentCrudController.php:

public static function getEntityFqcn(): string
{
    return Comment::class;
}

public function configureFields(string $pageName): iterable
{
    return [
        IdField::new('id')->hideOnForm(),
        TextField::new('author'),
        TextareaField::new('text')->hideOnIndex(), // Removing ->hideOnIndex() will display a link to a text modal
        EmailField::new('email'),
        DateTimeField::new('createdAt')->hideOnForm(),
        ImageField::new('photoFilename', 'Photo')->setBasePath('/uploads/photos')->hideOnForm(),

        AssociationField::new('conference')
    ];
}

src/Controller/Admin/ConferenceCrudController.php

public static function getEntityFqcn(): string
{
    return Conference::class;
}

public function configureFields(string $pageName): iterable
{
    return [
        IdField::new('id')->hideOnForm(),
        TextField::new('city'),
        TextField::new('year'),
        BooleanField::new('isInternational'),
        IntegerField::new('commentCount', 'Comments')->hideOnForm()
    ];
}

在 src/Entity/Conference.php 我添加了以下内容以使其commentCount可用:

public function getCommentCount(): int
{
    return $this->comments->count();
}

为了在提交评论时自动生成 createdAt 日期时间,我首先安装了以下包:

$ composer require stof/doctrine-extensions-bundle

然后修改 config/packages/stof_doctrine_extensions.yaml:

stof_doctrine_extensions:
    default_locale: en_US
    orm:
        default:
            tree: true
            timestampable: true

private $createdAt最后在 src/Entity/Comment.php 中装饰如下:

/**
 * @var \DateTime
 * @ORM\Column(type="datetime")
 * @Gedmo\Mapping\Annotation\Timestampable(on="create")
 * @Doctrine\ORM\Mapping\Column(type="datetime")
 */
private $createdAt;
于 2020-10-01T11:26:26.880 回答
1

就我而言

第一的

composer remove doctrine/common

接着

 composer require easycorp/easyadmin-bundle v2.3.9 doctrine/common v2.13.3 doctrine/persistence v1.3.8

有了它,它适用于这本书

于 2020-09-23T15:45:28.677 回答
0

对我来说,最清晰、最完整的解释是对@AnnaHowell 的回答,我只会更改您的部分代码。在src/Controller/Admin/CommentCrudController.php中:

 public function configureFields(string $pageName): iterable
{
    $avatar = ImageField::new('photoFilename')->setBasePath('uploads/photos/')->setLabel('Photo');
    $avatarTextFile = TextField::new('photoFilename');
   
     {
        yield     TextField::new('author');
        yield     TextEditorField::new('text');
        yield     TextField::new('state');
        yield     EmailField::new('email');
        yield     DateTimeField::new('createdAt', 'Created')->setFormat('dd-MM-y HH:mm:ss')
                ->setSortable(true)->setFormTypeOption('disabled','disabled');
        if (Crud::PAGE_INDEX === $pageName) {
        yield ImageField::new('photoFilename')->setBasePath('uploads/photos/')->setLabel('Photo');
    } elseif (Crud::PAGE_EDIT === $pageName) {
       yield TextField::new('photoFilename')->setLabel('Photo');
    }      
       
};

因此,我们允许管理员不仅评估文本,还评估照片的相关性。如果评论有很棒的文字,但照片不方便或琐碎怎么办?管理员可以删除照片的名称(这样就不会显示),留下文字评论并发布。

于 2020-10-25T23:48:10.610 回答
0

只需将所有内容复制/vendor/easycorp/easyadmin-bundle/src/Resources/publicpublic/bundles/easyadmin

于 2020-10-31T01:28:27.993 回答
0

简短的回答:

确保您使用 HTTPS 访问管理路由。即使管理员路由应该使用 debug:router 命令中的任何方案。

详细解答

同样的情况,可以用 Symfony 4.4 和 Symfony 5.2 和 Easyadmin 3.2 重现

我发现我正在使用 http (WAMP) 访问我的服务器:

网址 结果
http://localhost 200
http://localhost/admin 404

然后我尝试了

symfony console server:start

注意到有关安装证书的警告,安装它并再次运行 symfony 服务器。

之后我就可以使用 HTTPS,并且可以在 https://localhost/admin 上访问管理员

于 2021-02-26T07:56:02.057 回答