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?
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;
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With