Custom routing CakePHP 3


#1

I’m trying to create SEO friendly routing. I have a website with hotels and hotel rooms. I want to create a route progression that routes to different controllers/actions.

I want my urls to look like www.hotelwebsite.com/language/hotel-name/room-name

Here are the three routes I need:

If the url has a language parameter + 2 parameters:

$routes->connect('/:language/:hotelname/:room/', ['controller' => 'rooms', 'action' => 'viewRoom']); 

where

public function viewRoom($hotel_slug, $room_slug)

in which

:hotelname == $hotel_slug and :room == $room_slug

If the url has a language parameter + 1 parameter:

$routes->connect('/:language/:hotelname/', ['controller' => 'hotels', 'action' => 'viewHotel']);

where

public function viewHotel($hotel_slug)

in which

:hotelname == $hotel_slug

Otherwise use my standard route

$routes->connect('/:language/:controller/:action/*');

Is this even remotely possible?