Php Symfony,细枝传输数据

Php Symfony,细枝传输数据,php,symfony,routing,twig,Php,Symfony,Routing,Twig,在symfony中,我有一根细枝,我想传输数据以供操作,但在url中,我不想看到“角色”,仅传输以供操作,如何做到这一点? 路由: 细枝: 我明白了: DashboardController.php on line 138: Request {#7 ▼ +attributes: ParameterBag {#10 ▶} +request: ParameterBag {#8 ▶} +query: ParameterBag {#9 ▶} +server: ServerBag {#13 ▶} +fil

在symfony中,我有一根细枝,我想传输数据以供操作,但在url中,我不想看到“角色”,仅传输以供操作,如何做到这一点? 路由:

细枝:

我明白了:

DashboardController.php on line 138:
Request {#7 ▼
+attributes: ParameterBag {#10 ▶}
+request: ParameterBag {#8 ▶}
+query: ParameterBag {#9 ▶}
+server: ServerBag {#13 ▶}
+files: FileBag {#12 ▶}
+cookies: ParameterBag {#11 ▶}
+headers: HeaderBag {#14 ▶}
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: "/39/edit/116/submit"
#requestUri: "/app_dev.php/39/edit/116/submit"
#baseUrl: "/app_dev.php"
#basePath: null
#method: "GET"
#format: null
#session: Session {#151 ▶}
#locale: null
#defaultLocale: "en"
}

DashboardController.php on line 138:
"ROLE_COMPANY"
我尝试在我设置的索引操作中传输$role indexAction->editAction:

public function indexAction($username)
{
    $user_role = $user->getRoles();
    $request->getSession()->set('role', $user_role[0]);
在表单中,我有动作hoe在这个动作中传递这个$role,但这个角色不是外接程序路由:

<td>
  <a href="{{ path('artel_admin_index', {'ida': user.id, 'id': developer.id}) }}"> {{ developer.firstname }} {{ developer.lastname }}</a>
</td>
我明白了

UserProfileController.php on line 69:
array:1 [▼
 0 => "ROLE_COMPANY"
]

UserProfileController.php on line 69:
"ROLE_COMPANY"

现在在索引操作中,我在模板中呈现?因为现在在indexAction中我呈现了一些数据,在模板中我有如果你想把一个变量从一个视图传递到接收控制器,你应该使用
POST
方法

您可以实现这一点,例如,提交表单

如果在执行上一个
操作时知道此数据,则可以在会话中存储此信息:

$request->getSession()->set('VARIABLE_NAME', $value);
然后用以下方法取回:

$value = $request->getSession()->get('VARIABLE_NAME');

你不能用GET,用POST。GET将始终为您提供一个查询字符串。创建一个小表单并使用它。为什么要通过表单提交
role
?您始终可以通过
$this->getUser()->getRoles()
从控制器中经过身份验证的用户获取角色。不,现在我有了$this->getUser()=null,那么您应该首先对用户进行身份验证。在我看来,通过表单传递角色似乎是一个安全缺陷。之后,您可以轻松地在每个请求中获取角色。正如您所知,在
索引
$role
,我将按照我的示例将其放入会话中
设置
不返回值。如果你想检查设置的值,你必须使用
get
this wotk但是在哪里传输请求,我更新问题在我的editAction中我有请求参数[]我更新问题对不起,但是我迷路了。。。您正在执行
indexAction
以呈现第一个模板。在这里,您将
角色
放入会话。然后,您不需要将
角色
传递给您的小树枝。通过
会话
    $user_role = $user->getRoles();
    $request->getSession()->set('role', $user_role[0]);
    $role = $request->getSession()->get('role');
    dump($user_role, $role);exit;
UserProfileController.php on line 69:
array:1 [▼
 0 => "ROLE_COMPANY"
]

UserProfileController.php on line 69:
"ROLE_COMPANY"
$request->getSession()->set('VARIABLE_NAME', $value);
$value = $request->getSession()->get('VARIABLE_NAME');