Search code examples
phproutessymfony1

Symfony 1.4 create route for pdf files


I want to create routing for following urls.

Everything begins pdf and ends with .pdf

site.com/en/pdf/aaa/bbb/file.pdf
site.com/pdf/aaa/bbb/file.pdf
site.com/pdf/file.pdf
...

My code is:

global_pdf:
  class: myRequestRoute
  url: /:sf_culture/pdf/*/*.pdf
  param: { module: pdf, action: showEmbed }
  requirements: { sf_method: get }

But it doesn't work.

How do that ?

Thank you.


Solution

  • You have four different scenarios your routing needs to cover:

    1. route must match exact format: site.com/pdf/file.pdf
    2. route must match with language before pdf: site.com/en/pdf/file.pdf
    3. route must match with anything after pdf: site.com/pdf/aaa/bbb/file.pdf
    4. route must match with language before and anything after pdf: site.com/en/pdf/aaa/bbb/file.pdf

    The following routes should cover each of the above.

    global_pdf_1:
    class: myRequestRoute
    url: /pdf/:filename.pdf
    param: { module: location, action: test }
    requirements: { sf_method: get }
    
    global_pdf_2:
    class: myRequestRoute
    url: /pdf/:anything/:filename.pdf
    param: { module: location, action: test }
    requirements: { sf_method: get, anything: .* }
    
    global_pdf_3:
    class: myRequestRoute
    url: /:sf_culture/pdf/:filename.pdf
    param: { module: location, action: test }
    requirements: { sf_method: get }
    
    global_pdf_4:
    class: myRequestRoute
    url: /:sf_culture/pdf/:anything/:filename.pdf
    param: { module: location, action: test }
    requirements: { sf_method: get, anything: .* }