Download the PHP package marcin-jozwikowski/easy-admin-pretty-urls without Composer
On this page you can find all versions of the php package marcin-jozwikowski/easy-admin-pretty-urls. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download marcin-jozwikowski/easy-admin-pretty-urls
More information about marcin-jozwikowski/easy-admin-pretty-urls
Files in marcin-jozwikowski/easy-admin-pretty-urls
Package easy-admin-pretty-urls
Short Description Semi-automatic URL generator for pretty REST-like URLs in EasyAdmin
License MIT
Informations about the package easy-admin-pretty-urls
EasyAdmin Pretty URLs
Symfony Bundle that introduces customizable routes to EasyAdmin
Example
Turn
into
Instalation
-
Install the bundle by running
-
Enable the bundle by adding it to your
config/bundles.php
if not enabled automatically -
Add a routes set pointing to a directory containing your Controllers
The
resource
is a directory path relative to your projects root directory. Type must always equal topretty_routes
. See Fine-tuning / Define routes manually section to learn how this step can be ommitted.Other routing structures can be utilized as well, for example:
- Make your main DashboardController extend
\MarcinJozwikowski\EasyAdminPrettyUrls\Controller\PrettyDashboardController
or manually override the a default template like so:
Configuration
The following parameters are in use:
Parameter | Default value | Description |
---|---|---|
route_prefix |
"pretty" |
First part of route name |
default_dashboard |
"App\Controller\EasyAdmin\DashboardController::index" |
Default controller action to invoke if not specified in attributes |
default_actions |
["index", "new", "detail", "edit", "delete", "batchDelete", "renderFilters", "autocomplete"] |
Default set of actions to build routes against |
include_menu_index |
false |
Should menu index be included in path |
drop_entity_fqcn |
false |
Should entityFqcn be removed from the URLs |
To change the default values set the parameter in your services.yaml
Or create a config/packages/easyadmin_pretty_urls.yaml
file with
Twig
There are one function, and one filter being registered by a Twig extension in this bundle:
pretty_urls_include_menu_index()
Function returns theinclude_menu_index
value from Configuration|pretty_urls_remove_actions
Filter removed the unnecessary query elements from the URL string
Fine-tuning
-
Define custom URL path
By default, the URL is created as
<class_name>/<action_name>
.To change that behavior specify
path
value inPrettyRoutesController
attribute for the whole controller, and/or inPrettyRoutesAction
attribute for the specific action.The following configuration will result in the action URL of
special/list
instead of the defaultany_fancy/index
. -
Putting entityID in the path
With a custom path defined in
#PrettyRoutesAction
attribute, it is possible to include the entityID in the path.To achieve it, simple add
{entityId?0}
to thepath
argument i.e.Due to the way form actions are generated by EasyAdmin it is necessary to specify a default value for the parameter in the path.
It does not have to be
0
but keep in mind that setting it to an existing ID will make the application unusable. -
Select actions to create routes for
By default, pretty routes are generated for
index
,new
,detail
,edit
,delete
,batchDelete
,renderFilters
, andautocomplete
actions.To change them globally set a proper configuration value. For a single-controller change add a
PrettyRoutesController
attribute to the controller and name the actions you want to have pretty routes for, inactions
parameter.You can also just add your custom actions to the default list by specifying
customActions
inPrettyRoutesController
attribute. -
Define routes manually
Instead of defining a
pretty_routes
routes to automatically parse all classes in a directory you can create routes that will replace your default EasyAdmin CRUD actions.controller
value must point to your projects DashboardControllerdefaults
crudControllerFqcn
andcrudAction
must point to your target CRUD controller and its action.path
can be anything of your choosing- Route name must match the pattern
<prefix>_<name>_<action>
with <action>
equal tocrudAction
value from the defaults<name>
being the target controller class name (not FQCN - just the last part) stripped ofController
, written in _snakecase<prefix>
is set topretty
by default. See Configuration to ways to change it.- When routes are defined manually the Installation step 3 is not required.
You can generate a YAML routes configuration for existing controllers for further manual modifications by running
Troubleshooting
-
Routes not working
If your routes are still not generated despite being added, check your logs for
'Pretty route not found'
withdebug
level. Those will list all the EasyAdmin routes that did not have their pretty counterparts.Most probably, there's some naming mismatch.
-
Checking the Resource parsing results
To see what is the outcome of parsing a
pretty_routes
Resource run the following command:
All versions of easy-admin-pretty-urls with dependencies
symfony/framework-bundle Version ^5.4|^6.0|^7.0
easycorp/easyadmin-bundle Version ^4.8.10 <4.14.0