Ad

How Can Other Users View A User's Profile Details In Octobercms?

- 1 answer

Displaying a user's information to the user is pretty much straight forward using their id or name in the url as parameter and displaying specific details using {{ user.name }}, {{ user.phone }} etc. But how can i display a specific user info to other users. When i click on www.example.com/profile/joe, it takes me to joe's profile. Trying it logged out or from a different account throws up an error.

This what i have done so far. my profile url has

 url = "/:id"

and my php block

 [session]
 ==
 <?php function onStart(){
$profile = $this->param('id');  
} 
?> 
== 

this links up to the profile page

<a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" 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 }} etc shows all the logged in user's info. I am just at lost here how to make the profile of a user available to other users.

Edit: Currently working if i use $userProfile = Auth::findUserById($profile)

connected to <a href = ''{{ id: users.id }}''>View Profile></a>

It still works if I change it to $userProfile = Auth::findUserByLogin($profile) connected to <a href = ''{{ id: users.username }}''>View Profile></a> or <a href = ''{{ id: users.email }}''>View Profile></a>

but i would have loved it to work using a different field

<a href = ''{{ id: user.company_name }}''>View Profile></a> instead of id or login details

Ad

Answer

Suppose we are generating link : www.example.com/profile/joe

so id will be joe now we need to find that user's record and use it

to find it in code

[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();
} 
?> 
== 

use it in template

{{ userProfile.name }}, {{ userProfile.phone }}

if any doubts please add comment.

Ad
source: stackoverflow.com
Ad