Display data based on logged in user

Display data based on logged in user

ratkinsonratkinson Posts: 9Questions: 0Answers: 0

I want to filter datatables + editor to display data that match the id of the logged in user only. Can someone lead me on the right path?

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Are you using the PHP libraries for Editor? If so I would recommend using the where() method - something like:

    $editor->where( 'user_id', $_SESSION['user_id'] );
    

    For example might do the trick.

    Docs for where().

    Allan

  • ratkinsonratkinson Posts: 9Questions: 0Answers: 0

    i tried using the where as shown below, and it gives me what im looking for but not sure how to get the id of the logged in user.

    ->where($key = "employer_id", $value = 77, $op = "=")

    when i try your way, it says "invalid json response".

  • ratkinsonratkinson Posts: 9Questions: 0Answers: 0

    i am using php libraries for Editor.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    ->where($key = "employer_id", $value = 77, $op = "=")

    Send only the values to where() :

    ->where( "employer_id", 77, "=")

  • ratkinsonratkinson Posts: 9Questions: 0Answers: 0

    That was just a test case and it worked but the i want the data with the same id as the logged in user id to be displayed.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited November 2014

    So how are you saving logged-in user id's? Allan assumed you were saving them to the session.

  • ratkinsonratkinson Posts: 9Questions: 0Answers: 0

    The application is built using cakephp so to get the user id i could just use the Auth component but i am not saving a php session.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    In which case, you need to use the Auth component as you say. As tangerine notes my code was just an example of how you can use where() to apply a WHERE condition to the queries Editor performs. I don't know the inner workings of your software and where the user id actually is. You would use that variable, whatever it might be, in the where() statement.

    Allan

  • ratkinsonratkinson Posts: 9Questions: 0Answers: 0
    edited December 2014

    ok thanks.

This discussion has been closed.