Custom Content Category Routing

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
TCR_500
Registered User
Posts: 176
Joined: Thu Mar 19, 2009 11:30 pm
Name: Timothy Chapman
Contact:

Custom Content Category Routing

Post by TCR_500 »

I'm trying to develop an extension that categorizes content somewhat like how the forum navigation work, but with the category names appearing in the URL in addition to what is shown in the navigation bar. For example:

What the URL should look like:
category\name\content
category-name\content
other\category\name\content

And the navigation bar would be:
Category < Name < Content
Category Name < Content
Other < Category < Name < Content

The documentation doesn't seem to cover this. So how do I get the URL routing to behave the way I want it to?

I tried something like this, but it didn't work:

Code: Select all

acme_demo_index:
        path: /custom
        defaults: { _controller: acme.demo.controller:handle }
acme_demo_viewcategory:
        path: /custom/{categories}
        defaults: { _controller: acme.demo.controller:handle }
acme_demo_viewcontent:
        path: /custom/{categories}/{name}
        defaults: { _controller: acme.demo.controller:handle }
EDIT: I also couldn't find anything from the search results.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Custom Content Category Routing

Post by mrgoldy »

What does not work?
When you go to that path, the handle($categories, $name) function is called in your controller. And depending on the variables (categories and name) you can display your page.
What you could do, not sure if its necessary, but is add defaults for the variables.

Code: Select all

acme_demo_index:
        path: /custom
        defaults: { _controller: acme.demo.controller:handle, categories: '', name: '' }
acme_demo_viewcategory:
        path: /custom/{categories}
        defaults: { _controller: acme.demo.controller:handle, categories: '', name: '' }
acme_demo_viewcontent:
        path: /custom/{categories}/{name}
        defaults: { _controller: acme.demo.controller:handle, categories: '', name: '' }
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
TCR_500
Registered User
Posts: 176
Joined: Thu Mar 19, 2009 11:30 pm
Name: Timothy Chapman
Contact:

Re: Custom Content Category Routing

Post by TCR_500 »

posey wrote: Sat Feb 10, 2018 1:27 pm What does not work?
When you go to that path, the handle($categories, $name) function...
That explains a few things. But I'm not sure how I'd distinguish between category and content when a link is clicked or typed into the URL bar.

This will take some time for me to try-out, then I'll post back.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Custom Content Category Routing

Post by mrgoldy »

So if someone is going to your route, .../custom/awesome/stuff.
Then in your function handle($categories, $name), $categories = 'awesome' and $name = 'stuff'. So you can do your magic there.
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
Post Reply

Return to “Extension Writers Discussion”