Php Symfony转换为字符串URL

Php Symfony转换为字符串URL,php,symfony,url,Php,Symfony,Url,我使用以下方法打印转换为字符串的整数变量: public function __toString(){ return strval($this->id); } 我将其打印在我的twig文件中,效果很好,但当我的变量放入URL路径时,我遇到了一个问题,如下所示: <a href="{{ path('profilo_secondlevel', {'uid': user.idUserReferenced}) }}">{{ user.idUserReferenced }}&l

我使用以下方法打印转换为字符串的整数变量:

public function __toString(){
    return strval($this->id);
}
我将其打印在我的twig文件中,效果很好,但当我的变量放入URL路径时,我遇到了一个问题,如下所示:

<a href="{{ path('profilo_secondlevel', {'uid': user.idUserReferenced}) }}">{{ user.idUserReferenced }}</a>
#
假设您已经定义了一个为
profilo_secondlevel
路由服务的控制器,那么您将拥有如下路由配置:

app/config/routing.yml

然后,您可以在细枝模板上使用以下模板代码:

<a href="{{ path('profilo_secondlevel', {'uid': user.idUserReferenced}) }}">
{{ user.idUserReferenced }}
</a>


它应该会产生这样一个URL:
/profilo/secondo livelo/73.html

您可以在定义
profilo\u secondlevel
路由的地方添加routing.yml(或控制器注释)的代码吗?它应该类似于
/profilo/secondo livelo/{uid}
。我编辑了我的帖子并添加了我的routing.yml,但使用您的解决方案,@sentenzaI将路径添加到
routing.yml
。它与
profilo\u secondlevel\u www.It
路线大致相同。
    ################################################################################
 #                               /profile/secondo_livello                                    # 
 profilo_secondlevel:
host:      "{_locale}.{domain}"
locales:  { it: "/profilo/secondo-livello.{_format}", fr: "/profilo/secondo-livello.{_format}", de: "/profilo/secondo-livello.{_format}" }
defaults:  { _locale: "%locale%", domain: "%domain%", _format: "html", _controller: DtEcBundle:Profile:secondLevel }
requirements:
    _locale: "it|fr|de"
    domain:  "%domain%"
    _format:  "html|json"

 profilo_secondlevel_www.it:
path:      /profilo/secondo-livello/{uid}.{_format}
host:      "www.{domain}"
defaults:  { _locale: "%locale%", _format: "html", _controller: DtEcBundle:Profile:secondLevel }
requirements:
    _locale: "%locale%"
    domain:  "%domain%"
    _format:  "html|json"
  profilo_secondlevel_nowww.it:
path:      /profilo/secondo-livello/{uid}.{_format}
host:      "{domain}"
defaults:  { _locale: "%locale%",  _format: "html", _controller: DtEcBundle:Profile:secondLevel }
requirements:
    _locale: "%locale%"
    domain:  "%domain%"
    _format:  "html|json"
profilo_secondlevel:
  host:      "{_locale}.{domain}"
  path:      /profilo/secondo-livello/{uid}.{_format}
  defaults:  { _locale: "%locale%", domain: "%domain%", _format: "html", _controller: DtEcBundle:Profile:secondLevel }
  requirements:
    _locale: "it|fr|de"
    domain:  "%domain%"
    _format:  "html|json"
<a href="{{ path('profilo_secondlevel', {'uid': user.idUserReferenced}) }}">
{{ user.idUserReferenced }}
</a>