Solved: Filtering by User who logs in

ahmedo

Member
Hi,

Yet another question. Sorry about that.

I need to create a menu that shows records that were entered only by the User who logged in.
I tried few combinations but some how it did not work.

Thanks.


Sent from my iPhone using Tapatalk
 
To filter a list by user ID, assuming you have a user element (or some other element that stores the user ID of the creator) called 'user_id', you would set up a pre-filter on either the menu's list settings, or the main list settings, as:

Field: user_id (raw)
Condition: EQUALS
Value: {$my->id}
Type: text
Apply to: Public

Note that if you set the prefilter on the menu, it can easily be bypassed by simply leaving off the Itemid from a link directly to the list, so menu prefilters should not be considered "secure" in any way. If you put the prefilter on the list itself, then all access to the list will be filtered.

-- hugh
 
Thanks Hugh. It worked with the first attempt. A rare occasion in my life. :)

BTW, is the $my->id a Joomla var or Fabirk? If it is a Joomla var, is there anything for current Menu selected. I want to be able to display Welcome xxx to yyy (xx would be the user name - that I got already), yyy would be the Menu name?

Tnank you again.
 
Anything in {} is Fabrik placeholders. Although the history of why it's $my->id is Joomla ... back in the 1.x days, there was a global variable in Joomla for the logged on user called $my, so the logged on user ID was $my->id. You can also use {$my->name}, {$my->username}, {$my->email}, etc (anything that's in the #_users table).

But no, there isn't a placeholder for the current menu. You'd have to do that with a little custom code. Where do you want to put the welcome message? If it's in (say) a form or list intro, you could do it by using Sourcerer (from Regular Labs), and embedding a few lines of PHP:

Code:
{source}
<?php
$app = JFactory::getApplication();
$menuItem = $app->getMenu()->getActive();
$user = JFactory::getUser();

echo "Welcome " . $user->get('name') . " to " . $menuItem->title;
?>
{/source}

-- hugh
 
Today is my lucky day. For the second time I follow your instructions and get it right from the first time. Thank you very much once again.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top