Jump to content

Page Select with variable per user


anttila
 Share

Recommended Posts

First, I want to thank everyone who has been developing this great CMS. I really love it and I can do so much more and even learn more about coding. Now I try to create something new and very important for me, but I have a small problem with it.

I am trying to make a website where users only see their own stuff or blank / redirect if not logged in. The problem is that I want to use the same template for all users, so I can't put a certain page as parent for selectable pages because the parent should always be /clients/username/categories/ (different path for every user).

Input field type is Select or PageAutocomplete. User can create new categories through it.

I would also like to know if there is a way to prevent users to see only what they have under their own /clients/username without making new templates for all users. I only show what I want them to see through templates but if they know the admin url then they would see all the pages and they would have access to edit all the pages which are created with certain content type. They need only access to create new content under their own "main page". This user page is created when a new user is registered and linked with field (content of the field is user id).

Select is very important because every category gives special view for user.

user1

-- Project 1

---- Year

-------- Things that user creates from Page 1.

-- Categories

---- Things I want to use as Select List for new pages

-- Project 2

Link to comment
Share on other sites

Hello tewdin and welcome to the forum!

From your description I don't really get what you want to do exactly. Are you talking about the frontend or the admin area of your site?

In the frontend, if you only want to show pages to a user that "belong" to that user (were created by that user), there is $page->createdUser or in a selector created_users_id.

So to select only pages that were created by the logged in user, you can do

$pages->find("created_users_id={$user->id}");

To redirect non logged in users:

if(!$user->isLoggedin()) $session->redirect($pages->get("/login/")->url);

Hope this helps to get you started.

Link to comment
Share on other sites

The problem is that I want to use the same template for all users, so I can't put a certain page as parent for selectable pages because the parent should always be /clients/username/categories/ (different path for every user).

Rather than define a parent for selectable pages in your page field, try the "Custom PHP code to find selectable pages" option...

return $pages->find("parent=/clients/{$this->user->name}/categories/");
Link to comment
Share on other sites

I've used such limitations in the past and I can only advice you to be careful with the code. Surely users might only see their own categories in those pages, but you also need to consider what you're seeing (as superuser) when editing these pages or you'll empty out this field everytime you'd save the page. Also it's always to consider that for example processwire's lister will try and load the select box without specific user or page context for displaying it in it's filters.

Link to comment
Share on other sites

  • 3 months later...

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

×
×
  • Create New...