fosuserbundle - 在 FOSUserBundle 中查看其他用户的个人资料
问题描述
首先,对不起我的英语。
我有一个带有广告系统的网站。感谢 FOSUserBundle,访问他的个人资料非常简单。但我想公开其他用户的个人资料。让我解释一下,我希望我们点击一个用户的名字来查看他的个人资料。当我转储用户时,我有两个不同的用户:返回当前用户的 app.user 和返回撰写广告的用户的 ad.user。不幸的是,当我点击创建广告的用户时,它会自动发送到当前用户的个人资料:'(
我寻找了很多解决方案,但没有任何效果,ad.user 继续返回当前用户,尽管 url 指示广告作者的 id。
我在symfony 3上。请帮助我。
app.user 的转储 =
User {#405 ▼
#id: 1
#ville: "Angers"
#description: "Test description dans profil Modifé TEST 2!!"
-ads: PersistentCollection {#450 ▶}
-comments: PersistentCollection {#475 ▶}
#username: "superadmin"
#usernameCanonical: "superadmin"
#email: "superadmin@gmail.com"
#emailCanonical: "superadmin@gmail.com"
#enabled: true
#salt: null
#password: "$2y$13$lSKxx9k4ctd5BNBDEoCEGeHU1jHi7S8jD7o8jS01S1TNX/KK8.zH."
#plainPassword: null
#lastLogin: DateTime @1525031449 {#400 ▶}
#confirmationToken: null
#passwordRequestedAt: null
#groups: null
#roles: array:1 [▶]
}
ad.user 的转储 =
User {#740 ▼
+__isInitialized__: true
#id: 2
#ville: "Angers"
#description: null
-ads: PersistentCollection {#1057 ▶}
-comments: PersistentCollection {#1074 ▶}
#username: "usertest"
#usernameCanonical: "usertest"
#email: "usertest@gmail.com"
#emailCanonical: "usertest@gmail.com"
#enabled: true
#salt: null
#password: "$2y$13$3RhGWDCHt/uQn2EvLhuQ0es8dNOuwXhgiU/gtRKc3CzhQ7iWB.VUm"
#plainPassword: null
#lastLogin: DateTime @1525008711 {#1048 ▶}
#confirmationToken: null
#passwordRequestedAt: null
#groups: null
#roles: [] …2
}
是否有可能在某处有优先级强制访问当前用户的个人资料?
我在树枝中的代码:
<a href="{{ path('fos_user_profile_show', {'id': ad.user.id }) }}">Publiée par : {{ ad.user.username}} <span class="text-secondary">le {{ ad.date|date("d/m/Y") }}</span></a>
谢谢
解决方案
我发现 !!!!!!
在 ProfileController 我添加了一个新的 showIdAction:
/**
* @Route("/profile/{id}", name="profile_id", requirements={"id"="\d+"})
*/
public function showIdAction($id)
{
$user = $this->getDoctrine()
->getRepository('AppBundle:User')
->find($id);
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
return $this->render('@FOSUser/Profile/show.html.twig', array(
'user' => $user,
));
}
而且,在 profile.xml(FOSUserBundle 的路由)中,我添加了一个新路由:
<route id="profile_id" path="/{id}" methods="GET">
<default key="_controller">fos_user.profile.controller:showIdAction</default>
</route>
在树枝中:
<a href="{{ path('profile_id', {'id': ad.user.id }) }}
和它的工作。
如果其他人寻求解决方案,我将问题留在这里
推荐阅读
- python - 添加一个新的 cpython 关键字
- javascript - 用 JavaScript 做一个问答游戏,我如何创建一个数据库来保存用户的分数?
- javascript - MultiValueDictKeyError 在 Django 中访问相同的表单元素
- php - 使用 RewriteRule 后未打开 index.php
- c# - 无法在 V/Studio 2019 中“跨步”进入代码
- java - Thymeleaf - 不会显示 6 个 getter 方法中的 1 个
- ffmpeg - FFMPEG 中的 `-map data-re` 选项有什么作用?
- html - 如何使用响应式定位将最后一个列表项与底部对齐
- c - C中的Bspline基函数
- c# - C# WindowsForm 将 DatagridView 内容添加到 PowerPoint 的幻灯片中