0
votes

I have web based on Symfony framework. On web are routes to single (static) pages like '/about-us' or '/actions' so my routing annotation looks like:

/**
 * @Route("/{url}", name="front.singlePages.index")
 * @Template
 */
public function singlePageAction(Request $request, $url) {

// select url from db
// return content

(as i know symfony hasn't route priority so this class have name 'XSinglePage', because symfony ordering classes (like route base priority) by alphabet so for that is X on start)

But is there some keywords like '/bulgaria' or '/slovakia' for which ones i want another class so another route.

Q: Is there possibility to create the same route annotation with pattern /{url} (let's say in class List) with array of keywords which can fit in?

So in case url '/bulgaria' match route in class List with annotation '/{url}' but if key word not fit route was matched in class XSinglePage with annotation '/{url}'

Notice: I dont want adding another segment to route like '/singlePage/{url}' and '/list/{url}'

1

1 Answers

2
votes

You can do this with the routing requirements:

/**
 * @Route("/{url}", name="front.singlePages.keywords", requirements={"url"="keyword1|keyword2|keyword3"})
 * @Route("/{url}", name="front.singlePages.index")
 * @Template
 */
public function singlePageAction(Request $request, $url, $_route)
{
    // If you need specific code for a given route
    if ('front.singlePages.keywords' == $_route) {
        // 
    }