bwakad Posted May 19, 2014 Posted May 19, 2014 I had trouble with this selector which Even if not logged in - the current page (which is a user name), should give me info about that user and a list of items (pages) created by that user. My selector was originally this for logged in users - works and handy on user profile template: $selects = $pages->find("template=child-template, created_users_id={$user}"); // find pages user created But I was concerned about this part, because I want it also to be independent on a member page: created_users_id={$user} And needed to make it look like: ={$page->name} I could not use : $page->createdUser={$page->name} - since I am looking for other then current page. createdUser={$page->name} - since the field does not excist. $createdUser->name; - I would have to use $page in front which does not work for me, and $pages twice does not make sence. $user or $users - will not work because I look for $pages Then I browsed the API again... and used: $member = $users->get($page->name) ; which simply returns the ID of the user with that name Now I can set the selector to: created_users_id={member}; And, as always - if there are some things wrong I appreciate it if you let me know!
Pete Posted May 19, 2014 Posted May 19, 2014 Seems about right. Nothing wrong with the way you've done it, but the short one-line version would be: $userpages = $pages->find("template=child-template, created_users_id=" . $users->get($page->name)); Rather than using $selects all the time, I would name it something more meaningful like $userpages above, then iterate through them: foreach ($userpages as $userpage) { ... It's more descriptive when you build your template file up and there's lots going on - helps you keep track of things a bit easier especially when you're using multiple PageArrays on a page, though it's not essential to do this and everyone has their own preference and naming style. 1
adrian Posted May 19, 2014 Posted May 19, 2014 It's a built-in PW field in the Pages DB table, along with: modified_users_id created modified status sort etc...
bwakad Posted May 19, 2014 Author Posted May 19, 2014 Thanks, I actually tried that before, but since I am moving all my selectors inside a function I tested the selector but eventually have to use the string: $selector= "string here". After that I use $selects = $pages->find($selector); If I use more common names for what I select I would end up with so much variables inside the function.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now