I have a cakephp2 application where users login based on their credentials on a db. Authentication & Authorizations work fine.
I have a notes table, in which users's notes are stored. Each user can have many notes.
On one page I need to extract all the notes of the logged in user.
I have created a note model :
class Note extends AppModel {
public $name = 'Note';
public $belongsTo = 'User';
}
and in my user model I have:
class User extends AppModel {
public $name = 'User';
public $displayField = 'name';
public $hasMany = 'Note';....
In the usercontroller i have created:
public function getnotes($id = null) {
$this->User->id = $id;
}
but no matter what find statement I run, I can't get only the notes for the specific user. I run debug($id) and I get false on screen, so obviously the current user id is not being recognized.
I have to list all the notes of a user then link to each individual notes page.
Integrate an AUTH component in cakePHP ...so you will get logged in users ID/Info by auth functions and array like($this->Auth->user('id'))
for auth integration use below link as refence http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html
now use this user ID like this in finding records
$this->Note->find('all',array('conditions'=>array('Note.user_id'=>$this->Auth->user('id')))