12

I have fresh Symfony 5 project instlled locally, and added Easy Admin trought Symfony CLI:

symfony composer req admin

I should have /admin route but it's missing

I run:

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"

What am I missing?

Evgeny Ruban
  • 1,357
  • 1
  • 14
  • 20
platkos
  • 155
  • 1
  • 1
  • 7
  • yes, it is. I made a mistake here. the path is correct – platkos Jun 20 '20 at 12:44
  • I have the same problem! (Spanish version of the book) It seems like a joke but on page 94, it invites us to load the EasyAdmin, with the address / admin /, and the result is the same as yours – Jorge H Jul 30 '20 at 19:32
  • You will have to uninstall version 3 and install version 2. * of EasyAdmin. An explanation on how to uninstall a bundle is here: symfony.com/doc/3.4/bundles/remove.html, which can be applied in general to the Symfony 5 version. – Jorge H Jul 30 '20 at 21:02
  • Now if you run symfony console debug:router, /admin/ exists – Jorge H Jul 30 '20 at 21:06
  • For me, it seems installing easyadmin 2.3.4 solved the issue. Literally: `symfony composer req admin:2.3.4`. – Honza Hejzl Aug 31 '20 at 17:38

11 Answers11

14

You need to create at least one dashboard. Try:

php bin/console make:admin:dashboard

Next, you can create a CrudController with:

php bin/console make:admin:crud

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

Julien B.
  • 3,023
  • 2
  • 18
  • 33
  • Eh..., I followed Symfony 5: The Fast Track book and it supposed to be as easy as composer require & un-comment config in yaml... Thank You! – platkos Jun 22 '20 at 18:13
  • 2
    I don't know what book you are talking about, but easyadmin 3 was released 4 days ago, and has breaking changes from version 2. – Julien B. Jun 22 '20 at 20:51
  • Symfony 5: The Fast Track is the last book written by Fabien Potencier. He did not explain this two steps you mentionned. – Valimo Ral Jun 23 '20 at 14:39
  • 1
    As I mentioned the version 3 of EasyAdmin has been released only a couple days ago. Most likely your book is not up-to-date. So either change your easyadmin version to version 2 or use the doc for the version 3. – Julien B. Jun 25 '20 at 16:33
5

Yeah, I am reading this book right now and ran into the same issue.

First, make sure that your working directory is clean (run "git status" and remove all changes made by EasyAdminBundle setup).

Then run:

composer require easycorp/easyadmin-bundle:2.*

to install EasyAdminBundle version 2; with this version, you can proceed as described in the book.

hellomrbrown
  • 143
  • 1
  • 7
  • This solution seems reasonable, I also use Symfony 5.1.3 but I keep getting the same error: get / admin / the route not found – Jorge H Jul 30 '20 at 20:08
  • Now it works for me too! But you must manually add the files listed in the book: config / packages / easy-admin.yaml and config / routes / easy_admin.yaml Then add the book content for these files – Jorge H Jul 30 '20 at 20:21
5

As others have already said you need to create a dashboard with:

php bin/console make:admin:dashboard

And then create at least one crud controller. Since it seems you're using the Fast Track book, you need to type the following command twice and make one for both Comment and Conference:

php bin/console make:admin:crud

I am using the Fast Track book too and this is how my files ended up. I am still learning easy admin3 and thus make no claims as to best practice, but this should make the menus look as they do in the Fast Track screenshots:

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()
    ];
}

And in src/Entity/Conference.php I added the following to make commentCount available:

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

To generate the createdAt datetime automatically when the comment is submitted, I first installed the following bundle:

$ composer require stof/doctrine-extensions-bundle

And then modified config/packages/stof_doctrine_extensions.yaml:

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

And finally decorated private $createdAt in src/Entity/Comment.php with the following:

/**
 * @var \DateTime
 * @ORM\Column(type="datetime")
 * @Gedmo\Mapping\Annotation\Timestampable(on="create")
 * @Doctrine\ORM\Mapping\Column(type="datetime")
 */
private $createdAt;
Anna Howell
  • 439
  • 5
  • 7
3

EasyAdminBundle v3 have another configuration and you no longer need to use EasyAdminController resource.

You can find more information about it here

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

and here

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

Evgeny Ruban
  • 1,357
  • 1
  • 14
  • 20
3

When migrating from easyadmin 2 to 3, it appears that the route name is not preserved. One way to do this is in DashboardController, add

/**
 * @Route("/admin", name="easyadmin")
 */
public function index(): Response
{
    return parent::index();
}
Tac Tacelosky
  • 3,165
  • 3
  • 27
  • 28
3

I solved this problem as follows:

  1. Remove EasyAdmin 3
composer remove admin
  1. Install additional package.
composer require "easycorp/easyadmin-bundle":"^2.3"
  1. Update packages.
composer update
dvlden
  • 2,402
  • 8
  • 38
  • 61
1

In my case

first

composer remove doctrine/common

and then

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

With that it worked for the book

gerMdz
  • 71
  • 1
  • 5
  • That might work for "the book" but it's not helping using EasyAdmin 3. – Julien B. Sep 30 '20 at 02:45
  • It is true. My mistake. In my defense: It was the only place where I could write a response to another comment. And my English is very basic. – gerMdz Oct 01 '20 at 09:30
0

For me, the clearest and most complete explanation is the answer to @AnnaHowell I would only change a part of your code. In 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');
    }      
       
};

Thus, we allow the Administrator to not only evaluate the text, but also the relevance of the photo. What if a comment has great text, but an inconvenient or trivial photo? The Administrator could delete the name of the photo (and that way it would not be visible), leave the text comment and publish it.

Jorge H
  • 306
  • 1
  • 4
  • 19
0

Simply copy all of /vendor/easycorp/easyadmin-bundle/src/Resources/public to public/bundles/easyadmin

Clamburger
  • 617
  • 6
  • 24
Cadot.eu
  • 316
  • 1
  • 3
  • 15
0

Short answer:

Make sure you are using HTTPS to access the admin route. Even if the admin route is supposed to use any scheme in the debug:router command.

Detailed answer

Same situation, reproducible with Symfony 4.4 and Symfony 5.2 and Easyadmin 3.2

I found out that I was accessing my server with http (WAMP):

URL Result
http://localhost 200
http://localhost/admin 404

Then I tried with

symfony console server:start

Noticed the warning about installing the certificate, installed it and ran again the symfony server.

After than I was able to use HTTPS, and the admin was accessible on https://localhost/admin

prossel
  • 111
  • 1
  • 7
0

I was testing - easyAdmin4, with Symfony 6, with Lando backend, in Ubuntu.

No matter what I try, not only /admin routing, any of the controller was not working.

Make sure, if the issue is with EasyAdmin or with controllers.

The controller issue is resolved after

composer require symfony/apache-pack

From this post

Also, you can test /admin controller with

returning

  1. Twig Template (By Uncommenting) return $this->render('template1.html.twig'); and the template file will be present inside, templates/template1.html.twig
  2. Simple Response useing class Symfony\Component\HttpFoundation\Response;
  3. Or JSON data useing Symfony\Component\HttpFoundation\JsonResponse;

-- By default the /admin route will open default template return parent::index();

The Only solution seems to copy - .htaccess file inside public directory

# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex index.php

# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options +FollowSymlinks

# Disabling MultiViews prevents unwanted negotiation, e.g. "/index" should not resolve
# to the front controller "/index.php" but be rewritten to "/index.php/index".
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Determine the RewriteBase automatically and set it as environment variable.
    # If you are using Apache aliases to do mass virtual hosting or installed the
    # project in a subdirectory, the base path will be prepended to allow proper
    # resolution of the index.php file and to redirect to the correct URI. It will
    # work in environments without path prefix as well, providing a safe, one-size
    # fits all solution. But as you do not need it in this case, you can comment
    # the following 2 lines to eliminate the overhead.
    RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
    RewriteRule .* - [E=BASE:%1]

    # Sets the HTTP_AUTHORIZATION header removed by Apache
    RewriteCond %{HTTP:Authorization} .+
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]

    # Redirect to URI without front controller to prevent duplicate content
    # (with and without `/index.php`). Only do this redirect on the initial
    # rewrite by Apache and not on subsequent cycles. Otherwise we would get an
    # endless redirect loop (request -> rewrite to front controller ->
    # redirect -> request -> ...).
    # So in case you get a "too many redirects" error or you always get redirected
    # to the start page because your Apache does not expose the REDIRECT_STATUS
    # environment variable, you have 2 choices:
    # - disable this feature by commenting the following 2 lines or
    # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
    #   following RewriteCond (best solution)
    RewriteCond %{ENV:REDIRECT_STATUS} =""
    RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

    # If the requested filename exists, simply serve it.
    # We only want to let Apache serve files and not directories.
    # Rewrite all other queries to the front controller.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        # When mod_rewrite is not available, we instruct a temporary redirect of
        # the start page to the front controller explicitly so that the website
        # and the generated links can still be used.
        RedirectMatch 307 ^/$ /index.php/
        # RedirectTemp cannot be used instead
    </IfModule>
</IfModule>

Paul Bradbury
  • 482
  • 6
  • 8