0

I would like to create a filter that runs before the routing system does and am wondering if this is possible.

Specifically, I would like to parse and redirect URLs myself in certain situations using a filter. The urls that needed to be parsed using my filter will otherwise fall through all the rules in my routing.yml.

Currently what I'm doing is running the filter first in filters.yml, but when I need to redirect in my filter a variety of bad things happen:

  1. sfStopExceptions and sfError404Exceptions are thrown anyway and clutter up my logs (see this bug: http://trac.symfony-project.org/ticket/4741)
  2. I get a whole bunch of lines like this in my log:

[Mon Mar 07 14:24:48 2011] [error] [client 67.184.53.79] FastCGI: server "/var/local/fcgi/php-cgi-wrapper.fcgi" stderr: Empty module and/ or action after parsing the URL "/files/beezee50.png" (/)., referer: http://bee-zee-body-shop.blahblah.mobi/bee-zee-body-shop

[Mon Mar 07 14:24:53 2011] [error] [client 67.184.53.79] FastCGI: server "/var/local/fcgi/php-cgi-wrapper.fcgi" stderr: Action "beezeebodyshop/index" does not exist.

If I was able to redirect successfully before the routing was done, none of this should happen.

j0k
  • 22,600
  • 28
  • 79
  • 90
Josh Nankin
  • 2,518
  • 4
  • 28
  • 45
  • Noramlly i would address something like this with Rewrite, Redirect, or RedirectMatch rules in .htaccess... if it was so complex it needed to be parsed with php then i would probably make a custom Route and/or Routing class. Can you give us some insight why youre trying to redirect with a filter? – prodigitalson Mar 28 '11 at 15:07

1 Answers1

2

I would subclass sfPatternRouting (which is the most common sfRouting instance configured in the application's factories.yml file), to handle those special cases you need to address, and do the regular stuff otherwise.
You can set up your new routing class like this in the factories.yml:

all:
  routing:
    class: yourAdvancedRouting
    param:
      generate_shortest_url:            true
      extra_parameters_as_query_string: true
      any_other_param_you_need:         value
Imi Borbas
  • 3,683
  • 1
  • 19
  • 16