可能是晚了,但它可以幫助其他人
我正面臨與Symfony和FOSUserBundle相同的問題。
在FOSUserBundle個人資料鏈接爲:
SITE_URL /資料/
SITE_URL /型材/編輯
SITE_URL /型材/更改密碼
我有一個管理和儀表板,和我想要的鏈接,在管理面板
SITE_URL /管理/資料/
SITE_URL /管理/配置文件/編輯
SITE_URL /管理/配置文件/更改密碼
,並在用戶面板
SITE_URL /儀表板/型材/
SITE_URL /儀表板/型材/編輯
SITE_URL /儀表板/型材/變化 - 密碼
要獲得這種行爲是非常簡單的,而不事件偵聽和TwigExtesion
這裏的解決方案:
更換
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
通過
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_registration:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /{prefix}/profile
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /{prefix}/profile
在模板中使用:
<a href="{{ path('fos_user_profile_show', {'prefix': 'dashboard'}) }}">Show Profile</a>
<a href="{{ path('fos_user_profile_edit', {'prefix': 'dashboard'}) }}">Edit Profile</a>
<a href="{{ path('fos_user_change_password', {'prefix': 'dashboard'}) }}">Change Password</a>
或者你想
任何其他前綴現在,如果你使用例如更改密碼鏈接你會得到這個錯誤
一個例外模板的渲染過程中被拋出(「有些 強制性參數丟失(」前綴「)來生成 路由器的URL‘fos_user_change_password’。」)在 FOSUserBundle:ChangePassword:changePassword_content.html在線 3。
你可以在模板中添加前綴像這樣:
更換
<form action="{{ path('fos_user_change_password') }}" {{ form_enctype(form) }} method="POST" class="fos_user_change_password">
通過
<form action="{{ path('fos_user_change_password', {'prefix': app.request.attributes.get('prefix') }) }}" {{ form_enctype(form) }} method="POST" class="fos_user_change_password">
這會給你這個錯誤
一些強制性的參數缺少(「前綴」)來生成e路由「fos_user_profile_show」的 的URL。
我找到最終的解決方案是重寫控制器
只是在你的應用程序控制器文件夾中的孔CONTROLE複製,改變namesapce並更換
if (null === $response = $event->getResponse()) {
$url = $this->generateUrl('fos_user_profile_show');
$response = new RedirectResponse($url);
}
通過
if (null === $response = $event->getResponse()) {
$url = $this->generateUrl('fos_user_profile_show',array('prefix'=>$request->get('prefix')));
$response = new RedirectResponse($url);
}
在形式上你不需要這樣做,所以它會是
<form {{ form_enctype(form) }} method="POST" class="fos_user_change_password">
是的,這是有效的,但我試圖避免不得不把每個路口下的{宗教}佔位符放在/神下...想象一下,我有100條路線/神,我將不得不添加{宗教}佔位符每一個。如果相反,我將它添加到前綴我只會添加一次。 – Noquepoaqui