Jump to content

Company profile page - ideas?


bwakad
 Share

Recommended Posts

I have a profile page+file+template which is used for the logged in user to edit their details. A logged in user can be either a company or a member. 

In a perfect world when someone is browsing my website, I would have a link somewhere saying "more about this member" or "more about this company" and linking to a page. Which means - another guest/member/company can only see some details on a page.

But it puzzles me a bit since the user template, where extra fields can be added, is actually a core template file, and I read somewhere that it's main purpose is to be used in the back-end (I can be wrong).

I would like to know how exactly people have set this kind of thing up. Because I do not think every member/company would have a seperate page, aside from the user details. But to be bwakad - I am a litle confused how to do this the easy way.

In a former topic the solution to a user name which created a page was $child->createdUser->name;

But in this particular case I can't use $child->createdUser->url; as a link because it would open up the admin folder because it links to the admin/acces/users/name. That make me believe I have to use a seperate page. Any suggestions are welcome :-)

Link to comment
Share on other sites

A simple way is to use a "members" page with url segments. This page would be a normal page on the frontend, but would accept segments with the user names www.example.com/members/username. In your template you would do something like this:

$username = $sanitizer->name($input->urlSegment1); // make sure the user input can be a page name

$userPage = $pages->get("template=user, name={$username}"); // get the user with this name

if(!$userPage->id) throw new Wire404Exception(); // if this user doesn't exist show the 404 page

echo "<p>the name of this user is {$userPage->title}</p>";
  • Like 2
Link to comment
Share on other sites

I would like to know how exactly people have set this kind of thing up. Because I do not think every member/company would have a seperate page, aside from the user details. But to be bwakad - I am a litle confused how to do this the easy way.

Why not? Almost everything in ProcessWire is a page, so this would be a good way to go. Especially if the profile information will contain more details/fields than a plain user template. I might approach it like this:

  1. Create at least two templates - member and company.
  2. Create and add your user detail fields to these templates as appropriate.
  3. Create a Page reference field with a name like owner. This should be configured to reference template=user at the very least. This is the way user detail pages would be linked to actual user accounts.
  4. When a user registers, you would create a new page with the template as either member or company. Like this:
$profile = new Page();
$profile->of(false);
$profile->template = 'company';
$profile->title = 'Acme Widgets'; // but most likely from sanitised POST data
$profile->owner = wire('user'); // this links the new page to the logged in user
$profile->save();

You can find the user profile info like this:

$profile = wire('pages')->get("template=member|company, owner=$user");

I think this method has a few benefits:

  1. You don't need to modify the core user template.
  2. One user account could potentially manage multiple profiles if you wanted this to be the case in the future.
  3. A profile owner could be easily changed to someone else if necessary.
  4. Profile types can be easily changed later.
  5. Profile type can be identified by its template which should make it easier to differentiate when viewing or searching.

The code examples above haven't been tested, and are just an example of how it could be used :) You could even mix this in with diogo's suggestion - still have a template and page with URL segments, but using different templates for the profile information.

  • Like 3
Link to comment
Share on other sites

Okay, I have thought about it and decided to go with this:  I make 2 roles - 1 for members, 1 for companies.

login page

1. only visible in menu for guests.

2. after succesful login, check roles: member or company?

a. if role is company - make members listing page visible in menu > redirect to profile page

b. if role is member - make companies listing page visible in menu > redirect to profile page

profile page - to edit their details only - probably I use $user->name as menu title

1. only visible in menu for logged in users.

2. check roles: member or company?

a. if role is company - make owner role company details visible on page

b. if role is member - make owner role member details visible on page

listings page

1. only visible in menu for logged in users

2. check roles: member or company?

a. if role is company - display list of members

b. if role is member - display list of companies

details page

1. only visible in menu for logged in users

2. check roles: member or company?

a. if role is company - display requested member details

b. if role is member - display requested company details

With this in mind I need 4 pages, files and templates.

The profile template would hold all required fields for member AND company, but only visible according to the user role (set in the template file).

I hope I am doing this right...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...