Hi!
How do I show only the records of the current logged in user?
Following situation as an example:
I have the model Project, Issue and User. Project and User are in an many-to-many-relation. I have a table "user_project_assignment" which saves the id of a user and the id of the associated project.
In the models Project I have this relation defined: ‘users’ => array(self::MANY_MANY, ‘User’, ‘user_project_assignment(project_id, user_id)’) and in the model User I have defined this relation: ‘projects’ => array(self::MANY_MANY, ‘Project’, ‘user_project_assignment(user_id, project_id)’).
Now currently all created projects are displayed. I want that the logged in user can only see the projects which he created, so all projects which are associated to his user id.
I think I have to add a criteria to the Dataprovider in the actionIndex() method in the ProjectController. But I don’t know how to do it? How can I get only the records of the project table which are in the user_project_assignment table associated to the current logged in user?
Also I want that the logged in user is allowed to view and delete only the projects which he created. So I think I have to put this logic into the actionView and actionDelete methods when I know how to implement this for the actionIndex, but maybe there is a simple solution so that all actions for the projects and issues are only allowed, if the projects are associated to the logged in user.
Would really appreciate your help because I searched for several hours a solution but wasn’t able to find what I need. Maybe I searched not correctly… Hopefully somebody can help me. If you need more information please ask.
Thx.
Waldemar
PS: I’m new to Yii and I’m also not perfect at PHP. I’m studying informatics and still learning.