Navigation

Implementing URL Routing in Yves

The words contained in an URL play a major factor for search engine to determine if the page is relevant for a specific search query. The URL routing is a mechanism used to map URLs to the code that gets executed when a specific request is being submitted. URL routing makes URLs more human readable and SEO friendly.

To implement URL Routing in Yves:

Scenario: We need to route requests made on URL /hello to the action helloAction(Request $request) implemented in the DemoController controller.

To route this request, create a plugin that extends AbstractYvesControllerProvider in the module where the controller is defined, under thePlugin/Provider folder. AbstractYvesControllerProvider enables setting up the HTTP method used (GET or POST) when setting up the new route. It also enables to setup redirect URLs.

<?php
function createRedirectController($path, $name, $redirectPath, $status = 302)
function createGetController($path, $name, $bundle, $controllerName, $actionName = 'index')
function createPostController($path, $name, $bundle, $controllerName, $actionName = 'index', $parseJsonBody = false)
function createController($path, $name, $bundle, $controllerName, $actionName = 'index',$parseJsonBody = false)

In the new created plugin, you must setup the route in the defineControllers(Application $app) operation.

<?php
protected function defineControllers(Application $app)
{
    $this->createController('/hello', 'hello', 'Demo', 'Demo', 'hello');
}

Activate the plugin in : Pyz\Yves\Application\YvesBootstrap::getControllerProviderStack():


protected function getControllerProviderStack($isSsl)
	{
		return [
		   //...
			new HelloSprykerControllerProvider($isSsl),
		];
	}

You can now access http://www.de.demoshop.local/hello in your browser to make a request using the newly configured route.