Routing question/problem

A forum for Bolt related questions / issues

Routing question/problem

Postby Banjovy » Sun Dec 22, 2013 4:15 am

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.
Banjovy
 
Posts: 2
Joined: Sun Dec 22, 2013 4:04 am

Re: Routing question/problem

Postby Banjovy » Sun Dec 22, 2013 9:39 pm

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
Banjovy
 
Posts: 2
Joined: Sun Dec 22, 2013 4:04 am

Re: Routing question/problem

Postby Bob » Sat Jan 18, 2014 10:43 am

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!
Bob
Lead Developer
 
Posts: 1374
Joined: Tue Nov 20, 2007 11:16 pm


Return to Bolt Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron