Search code examples
phpclassurlroutesshopware

How to use dashes in Shopware 5 controller route and how to start in with small letters?


As I know in php the class name should not include lines and shopware takes the class name as the route to the controller's action. Is it possible to have dashes in the route somehow and also have all letters be small?

Example of what needs to be achieved:

class example-name-for-route{
}

expected route:

www.example.com/example-name-for-route


Solution

  • The easiest way would be creating a SEO URL for your custom controller, so the naming of the controller class is not relevant. How this is done is explained here.

    Just subscribe to the event Shopware_CronJob_RefreshSeoIndex_CreateRewriteTable and call the method sInsertUrl of the sRewriteTable core class. The first parameter is 'sViewport=yourControllerName' and the second the actual URL you want the controller to be available at.