Retrieve user ID to include as a parameter in list filtering

peterk900

Member
How can I obtain the J! UserID so I can only show selected data in a list and also add the id to new records created ? Thanks.
 
http://fabrikar.com/forums/index.php?wiki/common-php-tasks/

Bottom of that page at User paragraph:
$user = JFactory::getUser();
$userid = $user->get('id');

If you need to filter then use this placeholder in filter:
{$my->id}
set it as WHERE id EQUALS TO {$my->id} eval as TEXT

You can also filter on menu item level. Set menu item option to view the list as Select row -1 where user_id (you table column with user id). You should use list filter, not menu item filtering which can be overriden, though.
 
Thanks to both OndrejH and troester.

I can capture user details as hidden fields ( id, name or username ) and then filter the list as you describe ( $my->id, $my->name etc.) . So the data the user creates is automatically stamped with his user name and when opens the page with the Fabrik list he sees just his data. A key requirement very easily implemented. Fantastic ! Thanks for your help.
 
I'm puzzled why a list with a filter on user id or name which works when viewed in the administrator interface fails to retrieve any records when the list is set up as a menu item and viewed in the front end. If I remove the pre-filter all the records are displayed. I thought the problem might be that the filter was on user name rather than id - but filtering by id makes no difference. Any thoughts welcome.
 
Peter, It is access level result.
Set up the filter to by applied to group you need. (I guess "Registered" in your case?.)
 
Thanks again OndrejH - I'd noticed the box but stupidly didn't connect its use with the problem I was having. As you suggested the pre-filter wants to be set to the Registered group and the Access settings for the list also needs to be changed to Registered.
The other mistake I made I think was assuming that when you move from a super user log-in at the back end you keep this log-in when you view the front end. Once I put the log-in form back on the front end ( I'd removed it because I intend to force all users to log-in to this site ) and then log-in as the user that I'm trying to test then it all works perfectly.

I think this issue is now truly resolved ! Thanks again.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top