0

In a custom extension I have created a few URL hooks as follows:

namespace MyExtension;

class Extension extends \Bolt\BaseExtension
{   

    public function initialize()
    {
        // audio sample management
        $this->app->match("/foo", array($this, 'foo'));
        $this->app->match("/bar", array($this, 'bar'));
    }

    function foo()
    {
        // ...
    }

    function bar()
    {
        // ...
    }
}

I can hit both these functions via a url like so:

  • example.com/foo
  • example.com/bar

... and both will execute.

However when I add a page binding into the routing.yml it breaks and it tries to look for foo and bar as if they were pages.

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

How can I have foo and bar without them being caught by this binding?

SOLUTION

Added the following routing snippet before my pagebinding route.

foobinding:
  path: /foo
  defaults: { _controller: 'MyExtension\Extension::foo' }
diggersworld
  • 12,770
  • 24
  • 84
  • 119

1 Answers1

2

Yes, this is a sticky one and "by design" in Silex/Symfony. The controller routes getting stacked, and first match wins.

In Bolt, initMountpoints() (where the routes.yml routes get set up) gets called just before initExtensions() so the application routes can't get wiped out by poorly designed or malicious extensions.

What I have done on one install is to set the extension routes in routing.yml and define the controller as MyExtension\Extension.

UPDATE
Here is what is in the routing.yml file that I am using, but on Bolt 2 beta.

sitemap: path: /sitemap.xml defaults: { _controller: 'Bolt\Extension\Gawain\CustomSitemap\Controller\Sitemap::sitemap' }

Note that the extended namespace is just compliance with version 2 standards, not special in regards to 'working'

Gawain
  • 1,568
  • 10
  • 8