首页 > 解决方案 > 其他用户如何在 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 或登录详细信息

标签: phplaraveloctobercms

解决方案


假设我们正在生成链接: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 }}

如果有任何疑问,请添加评论。


推荐阅读