【发布时间】:2019-06-01 19:29:17
【问题描述】:
使用 url 中的 id 或名称作为参数,并使用 {{ user.name }}、{{ user.phone }} 等显示特定的详细信息,向用户显示用户的信息非常简单。但是我如何向其他人显示特定的用户信息用户。当我点击 www.example.com/profile/joe 时,它会将我带到 joe 的个人资料。尝试注销或从其他帐户尝试会引发错误。
这是我到目前为止所做的。我的个人资料网址有
url = "/:id"
和我的 php 块
[session]
==
<?php function onStart(){
$profile = $this->param('id');
}
?>
==
这链接到个人资料页面
<a href="{{ 'profile'|page ({ id: user.name }) }}"><button style="font-family: arial" class="btn btn-sm btn-light rounded--lg-pill shadow rounded border col-6">View Profile</button></a>
使用{{ user.name }}、{{ user.phone }} 等显示所有登录用户的信息。我只是在这里迷失了如何使其他用户可以使用用户的个人资料。
编辑:
如果我使用$userProfile = Auth::findUserById($profile),目前正在工作
连接到<a href = ''{{ id: users.id }}''>View Profile></a>
如果我把它改成
$userProfile = Auth::findUserByLogin($profile)
连接到
<a href = ''{{ id: users.username }}''>View Profile></a>
或者
<a href = ''{{ id: users.email }}''>View Profile></a>
但我会喜欢它使用不同的领域来工作
<a href = ''{{ id: user.company_name }}''>View Profile></a> 而不是 id 或登录详细信息
【问题讨论】:
-
您没有努力提供有关您迄今为止使用代码示例尝试过的内容的更多信息,这使得很难提供准确的答案。对于上面的问题,您需要检索路由 URI 参数(joe),在数据库中搜索该特定别名并获取您需要的数据。
-
这是我到目前为止所做的。我的个人资料 url 有
url = "/:id"和我的 php 块[session] == <?php function onStart(){$profile = $this->param('id'); } ?> ==这个链接到个人资料页面<a href="{{ 'profile'|page ({ id: user.name }) }}"><button style="font-family: arial" class="btn btn-sm btn-light rounded--lg-pill shadow rounded border col-6">View Profile</button></a>使用 {{ user.name }}、{{ user.phone }} 等显示所有登录用户的信息。我只是在这里迷失了如何使其他用户可以使用用户的个人资料。 -
@DavidMakogon 我已经做到了。
标签: php laravel octobercms