1

I have work function:

public function index()
    {
        $this->set('tables', $this->Table->find('all'));
    }

But how show only column WHERE owner = logged user?

4
  • How do you know if user is logged in? How do you authenticate user? Commented Jun 10, 2015 at 13:17
  • public $components = array( 'Session', 'Auth' => array( 'loginRedirect' => array( 'controller' => 'tables', 'action' => 'index' ), 'logoutRedirect' => array( 'controller' => 'tables', 'action' => 'index' ), 'authenticate' => array( 'Form' => array( 'passwordHasher' => 'Blowfish' ) ) ) ); Commented Jun 10, 2015 at 13:21
  • public function isAuthorized($user) { // Admin can access every action if (isset($user['role']) && $user['role'] === 'admin') { return true; } // Default deny return false; } Commented Jun 10, 2015 at 13:21
  • Then @drmonkeyninja answer should be correct. Have you tried it? Commented Jun 10, 2015 at 13:26

1 Answer 1

1

You want to do something like this where $this->Session->read() returns the current authenticated user:-

$this->Table->find(
    'all',
    array(
        'conditions' => array('Table.user_id' => $this->Session->read("Auth.User.id"))
    )
);
Sign up to request clarification or add additional context in comments.

4 Comments

Parse error: syntax error, unexpected T_DOUBLE_ARROW
Sorry, typo. Fixed the answer. Forgot to include array after the conditions index.
Undefined variable: tables and Invalid argument supplied for foreach()
You shouldnt use (deprecated) static access, better $this->Session->read().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.