php - 其他用户如何在 octobercms 中查看用户的个人资料详细信息?
问题描述
{{ user.name }}
使用 url 中的 id 或 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>
using{{ 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 或登录详细信息
解决方案
假设我们正在生成链接:www.example.com/profile/joe
所以 idjoe
现在我们需要找到该用户的记录并使用它
在代码中找到它
[session]
==
<?php function onStart(){
$profile = $this->param('id');
$this['userProfile'] = Auth::findUserByLogin($profile);
// you can use other field if you need
// $this['userProfile'] = \RainLab\User\Models\User::where('username', $profile)->first();
}
?>
==
在模板中使用它
{{ userProfile.name }}, {{ userProfile.phone }}
如果有任何疑问,请添加评论。
推荐阅读
- node.js - Mongoose 查找,具有一个搜索参数的多个字段
- bioinformatics - 如何从 v. 0.11.6 开始为 fastQC 启用 kmer 图
- xml - 是否可以覆盖 apache-servicemix cxf.xml 文件?
- javascript - handlebar.js 中的条件 IF
- powershell - 如果是第 7 天和第 14 天,Send-MailMessage
- apache-spark - Databricks 中的 Z 排序
- android - 方法 '~/' 在 null 颤动上被调用
- google-search - Google for Jobs 显示的工作位置不正确(Google 正在使用我们的公司总部)
- matrix - 我不知道如何构建我想要的视觉效果
- matlab - 如何识别大文本文件中的一行,从下面的行读取值,并将它们保存到工作区