1

I am using CakePHP 3.1, I am trying to create a route that works like this pseudo code

:category/:sub-category/:slug
if(:subcategory doesn’t exist){ treat as :controller/:action }

:category/:controller/:action
:category/:controller

if(:controller doesn’t exist){ treat as action }

:category/:action

if(:action doesn’t exist){ then action is view use as slug }

:category/:slug


if(:slug doesn’t exist){return 404 }


:category/:sub-category/
connect( controller=>article, action=>view, :subcategory, :slug=>’home’
:category/)
connect( controller=>article, action=>view, :subcategory=>none , :slug=>’home’)

And the category would control the theme which changes the styles, this i would add in my ArticlesController.php

Is this even possible? If checking if something exist is out of scope of routes, I wouldn't mind doing a check inList. As the category and subcategory would be a fixed amount.

Is this to complicated for routes? should i just do this in the ArticlesController.php under the view action? and just do

$routes->connect('/:slug', ['controller' => 'articles', 'action' => 'view']);
drmonkeyninja
  • 8,490
  • 4
  • 31
  • 59
artSir
  • 540
  • 1
  • 8
  • 29
  • In Cake 2.x you can create custom route classes, so it should be very possible to achieve what you are proposing. I'm not sure how this works in 3.x, but here is a good blog by Martin Bean on the topic and how it works in 2.x: http://martinbean.co.uk/blog/2014/08/19/custom-route-classes-in-cakephp/ – gazareth Sep 23 '15 at 16:09
  • 1
    You are simply describing [custom route classes](http://book.cakephp.org/3.0/en/development/routing.html#custom-route-classes) - yes it's possible, but a bit too broad for stack overflow. `I wouldn't mind doing a check inList. As the category and subcategory would be a fixed amount` - that's a much simpler solution, and what I'd recommend. – AD7six Sep 23 '15 at 16:09
  • thanks i'm currently trying an explicit approach – artSir Sep 23 '15 at 16:19

0 Answers0