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.phpif not enabled automatically -
Add a routes set pointing to a directory containing your Controllers
The
resourceis 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\PrettyDashboardControlleror 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_indexvalue from Configuration|pretty_urls_remove_actionsFilter 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
pathvalue inPrettyRoutesControllerattribute for the whole controller, and/or inPrettyRoutesActionattribute for the specific action.The following configuration will result in the action URL of
special/listinstead of the defaultany_fancy/index. -
Putting entityID in the path
With a custom path defined in
#PrettyRoutesActionattribute, it is possible to include the entityID in the path.To achieve it, simple add
{entityId?0}to thepathargument 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
0but 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, andautocompleteactions.To change them globally set a proper configuration value. For a single-controller change add a
PrettyRoutesControllerattribute to the controller and name the actions you want to have pretty routes for, inactionsparameter.You can also just add your custom actions to the default list by specifying
customActionsinPrettyRoutesControllerattribute. -
Define routes manually
Instead of defining a
pretty_routesroutes to automatically parse all classes in a directory you can create routes that will replace your default EasyAdmin CRUD actions.controllervalue must point to your projects DashboardControllerdefaultscrudControllerFqcnandcrudActionmust point to your target CRUD controller and its action.pathcan be anything of your choosing- Route name must match the pattern
<prefix>_<name>_<action>with <action>equal tocrudActionvalue from the defaults<name>being the target controller class name (not FQCN - just the last part) stripped ofController, written in _snakecase<prefix>is set toprettyby 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'withdebuglevel. 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_routesResource 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