Page 1 of 1

Routing question/problem

PostPosted: Sun Dec 22, 2013 4:15 am
by Banjovy
I'm new to Bolt so this may be an easy issue, but I can't find anything on the discussion board for my problem.

I created a route to have all page content types to use /{slug} instead of /page/{slug}
routing.yml entry:
# Place your own routes here...
pagebinding:
path: /{slug}
defaults: { _controller: 'Bolt\Controllers\Frontend::record', 'contenttypeslug': 'page' }
contenttype: pages

All individual pages work fine, however, when I use the listing url /pages I get a exception error. Here's some of the error message text:
Symfony \ Component \ HttpKernel \ Exception \ HttpException
Page page/pages not found.

I guess I'm missing something else to change. Any feedback or help would be appreciated.

Re: Routing question/problem

PostPosted: Sun Dec 22, 2013 9:39 pm
by Banjovy
I may have resolved this problem. While documentation states custom routes should be placed first [first come first serve design], I found by placing the route after the contentlisting definition it appears to work as expected. Indiviual page urls display as desired and reference to /pages displays the pages url without a not-found message.

I'm assuming this is the correct way to handle this unless other feedback is provided on a better solution. Portion of the routing.yml config below:

Code: Select all
contentlisting:
  path:               /{contenttypeslug}
  defaults:           { _controller: 'Bolt\Controllers\Frontend::listing' }
  requirements:
    contenttypeslug:  'Bolt\Controllers\Routing::getPluralContentTypeRequirement'

# Custom route for pages.
pagebinding:
  path: /{slug}
  defaults: { _controller: 'Bolt\Controllers\Frontend::record', 'contenttypeslug': 'page' }
  contenttype: pages

Re: Routing question/problem

PostPosted: Sat Jan 18, 2014 10:43 am
by Bob
I found by placing the route after the contentlisting definition it appears to work as expected.


You are correct. You need to add your custom routes _before_ if you want to override default behaviour, and put them at the end to _extend_ default behaviour. If you put your own routes before, and they are to 'broad', the will trigger for some pages where you might not want that, and it might break things. I will make this more clear in the documentation. Thanks!