Symfony的:电子邮件地址作为请求参数电子邮件地址、参数、Symfony

由网友(别再沦陷)分享简介:我在使用过的电子邮件地址,网址为symfony的应用程序的一些问题。I'm having some issues with passing an email address in a url to a symfony app.网址看​​起来像example.com/unsubscribe/email/me@exa...

我在使用过的电子邮件地址,网址为symfony的应用程序的一些问题。

I'm having some issues with passing an email address in a url to a symfony app.

网址看​​起来像

example.com/unsubscribe/email/me@example.com

它总是导致 sfError404Exception ,当周期被去除的除外。各地做一些google搜索后,我所见过的唯一的解决办法是,htaccess是绕过,因为期间present的URL。然而,当我建议的修正添加到htaccess的,就像这样:

It will always result in a sfError404Exception, except when the period is removed. After doing some googling around, the only solution I've yet seen is that htaccess is bypassing the url because of the period present. However, when I add the suggested fix to htaccess, like so:

# we skip all files with .something
RewriteCond %{REQUEST_URI} ..+$
RewriteCond %{REQUEST_URI} !@.+    #skip email address
RewriteCond %{REQUEST_URI} .epl$
RewriteCond %{REQUEST_URI} !.html$ 
RewriteCond %{REQUEST_URI} !.rhtml$
RewriteRule .* - [L]

我会得到相同的404也将返回404,当我直接在URL中使用的前端控制器( example.com/index.php/unsubscribe/email/me@example.com )。我试图把转义版本直接在地址栏,如 example.com/unsubscribe/me%40example%2Ecom ,这工作,但只有在Firefox中,无处

I get the same 404. It also returns 404 when I use the front controller directly in the url (example.com/index.php/unsubscribe/email/me@example.com). I've tried putting the escaped version directly into the address bar, eg example.com/unsubscribe/me%40example%2Ecom and this works, but only in firefox, nowhere else.

我已经花了约2小时的论坛答案在这一点上谷歌搜索地狱,我跑出来的想法。

I've spent about 2 hours in forum answer googling hell at this point and I'm running out of ideas.

有什么想法?

感谢。

更新:这里是routing.yml中的相关章节:

Update: Here is the relevant section of the routing.yml:

unsubscribeform:
  url:  /unsubscribe/email/:email
  param: { module: subscribe, action: index }

更新:堆栈跟踪...看起来像它没有得到任何路由信息去给我

Update: Stack trace ... looks like its not getting any route information to go on to me

404 | Not Found | sfError404Exception
Empty module and/or action after parsing the URL "/unsubscribe/email/me@example.com" (/).
stack trace

1. at ()
  in SF_SYMFONY_LIB_DIR/controller/sfFrontWebController.class.php line 44 ...
          41.
          42.       if (empty($moduleName) || empty($actionName))
          43.       {
          44.         throw new sfError404Exception(sprintf('Empty module and/or action after parsing the URL "%s" (%s/%s).', $request->getPathInfo(), $moduleName, $actionName));
          45.       }
          46.
          47.       // make the first request
2. at sfFrontWebController->dispatch()
  in SF_SYMFONY_LIB_DIR/util/sfContext.class.php line 159 ...
         156.    */
         157.   public function dispatch()
         158.   {
         159.     $this->getController()->dispatch();
         160.   }
         161.
         162.   /**
3. at sfContext->dispatch()
  in /home/web/htdocs/index.php line 10 ...
           7. require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'ProjectConfiguration.class.php');
           8.
           9. $configuration = ProjectConfiguration::getApplicationConfiguration(SF_APP, SF_ENVIRONMENT, SF_DEBUG);
          10. sfContext::createInstance($configuration)->dispatch();

11。

推荐答案

在默认情况下,Symfony的治疗 / 为参数分隔符。 这使得它非常容易搭配一个url像这样:

By default, Symfony treats . and / as parameter separators. That makes it very easy to match a url like so:

/some/path/:param.:ext

但无助于电子邮件地址。

But doesn't help with email addresses.

幸运的是,你可以覆盖隔膜指定自己的模式。 只需添加要求行下面你的路由:

Fortunately, you can override the . separator by specifying your own pattern. Just add the requirements line below to your routing:

unsubscribeform:
  url:  /unsubscribe/email/:email
  param: { module: subscribe, action: index }
  requirements: { email: .+ }

+ 的要求,是一个普通的EX pression匹配任何东西。该匹配任何字符,而 + 表示匹配一个或更多的。

The .+ in the requirement is a regular expression matching anything. The .matches any character, and the + means match one-or-more.

(经过测试,在Symfony的1.4)

(Tested in Symfony 1.4)

阅读全文

相关推荐

最新文章