The most requested feature for EasyAdmin has just arrived in version 4.14.0.
Since day one, EasyAdmin has used query string parameters to pass the necessary
information for rendering backend pages. This approach created URLs like:
https://example.com/admin?crudAction=edit&crudControllerFqcn=App%5CController%5CAdmin%5CPostCrudController&entityId=3874
While this URL format is ugly, it's functional. Some browsers, like Safari, even
hide most of the URL by default, showing only the hostname, so the impact on
end-users is minimal.
However, starting today, EasyAdmin generates cleaner URLs that look like this:
https://example.com/admin/post/3874/edit
In addition to being the most requested feature, we implemented this change for
two main reasons:
This feature has been designed to work seamlessly with current applications. If
you don't make any changes, the application will still use ugly URLs, and
everything will continue to work as before.
If you'd like to start using pretty URLs now, create the following configuration
file in your application:
# config/routes/easyadmin.yaml easyadmin resource: . type: easyadmin.routes
This configuration enables a custom Symfony route loader, a class that
automatically generates routes in your application. Clear the cache (by running
php bin/console cache:clear or rm -fr var/cache/*) and the application will
begin using pretty URLs. Run the following command to see all the newly generated
routes:
php bin/console debug:router
You can now also update your code to stop building backend URLs with the
AdminUrlGenerator utility and use the new route names directly:
// Before: $this->adminUrlGenerator() // this is only needed if you have ore than 1 dashboard ->setDashboard(SomeDashboardController::class) ->setController(ProductCrudController::class) ->setAction('detail') ->setEntityId(321) ->generateUrl(); // After: $this->router->generate('admin_product_detail', ['entityId' => 321]);
The generated routes are composed of three parts: dashboard crud action. Each
of these can be customized using the new PHP attributes #[AdminDashboard],
#[AdminCrud], and #[AdminAction]. Read the docs to learn more.
Pretty URLs are still optional in EasyAdmin 4.x versions, but ugly URLs are now
deprecated. Starting in EasyAdmin 5.x (planned for release soon), pretty URLs
will be required.
✨ If you enjoyed this feature and want to see more like it, consider
sponsoring the EasyAdmin project ??
The above is the detailed content of New in EasyAdmin: Pretty URLs. For more information, please follow other related articles on the PHP Chinese website!