1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

$my->id not working in prefilter

Discussion in 'Community' started by chris.paschen, Feb 8, 2017.

  1. chris.paschen

    chris.paschen Chris Paschen

    Level: Community
    I'm trying to use a simple pre-filter on a menu item to display a list of the user's items from a table.

    In the menu item prefilter I have:

    OR
    Elements: UserID (name of field containing id of users' records)
    Condition: Equals
    Value: {$my->id}
    Type: Eval
    Access: Public

    However, when I try to use this menu item from the front-end I get the following error:

    0 syntax error, unexpected end of file

    I have also tried changing the Value to:
    '{$my->id}'

    With same results.

    Are these placeholders not available in the menu item prefilter area?
    Or is there some other issue?


    Running:
    J! 3.6.5
    Fabrik 3.5.2, Github as of 2017-02-06
    PHP 7.x
     
  2. lcollong

    lcollong FabriKant d'applications web

    Level: Community
    "eval" expects real php code such as "return '{$my->id}';"
    you should use "text"
     
  3. chris.paschen

    chris.paschen Chris Paschen

    Level: Community
    Thanks. I tried changing that to text (and also used real PHP code version).
    However then I didn't get an error; however, it was not returning any results.

    After doing quite a bit more testing, I found that as long as I have the element's OPTIONS | USER DATA set to "Name" it won't find a match. I have to switch it to ID.
    However, I need to have that set to "Name" for display purposes in other locations of my site.
    In the past I had the option to select <fieldname>(raw) in the menu pre-filters; however that didn't appear for me.
    After tracking it down, I found that on the specific element in LIST VIEW SETTINGS | FILTERS | FILTER DATA it must be set to 'Show all' to be able to select the 'raw' data in the pre-filter.
    (Hope that helps someone with similar issues in the future)
     
  4. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    In the pre-filter, for the "Field", are you selecting "UserID" or "UserID (raw)"?

    To match against {$my->id}, you have to select the "(raw)" option. The user element is just a special case of a join element, so has the concept of the "raw" value (the join key) or non-raw (the join label). In this case, the raw value (key) for the user element is the user id, and the non-raw (label) is whatever you are displaying (name, username, etc).

    -- hugh
     
  5. chris.paschen

    chris.paschen Chris Paschen

    Level: Community
    That was the strange thing. The "(raw)" option didn't appear in the pre-filter until I went to the LIST VIEW SETTINGS \ FILTERS | FILTER DATA for the element and set it to 'Show all'.

    I though that "Show all" was the default. Either that changed somewhere in the updates for Fabrik OR somebody else went in and changed it for this element before I started working with it.
     
  6. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Oh, sorry, I missed that bit.

    I'll take a look at that.

    --hugh
     
  7. cgray

    cgray New Member

    Level: Community
    I found this worked !
    pre-filters AND element 'X' condition> EQUALS
    value return'{$my->name}'; Type > Eval

    so logged in users only see in a list, forms assigned to them via element 'X'
     
  8. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    It's best to use user IDs, not names, because names can change.

    And you shouldn't have to use eval, type 'text' with just {$my->id} (or whatever) should work.

    -- hugh
     

Share This Page