Allow Users to view records that belong to a state that corresponds to the foreign key in their user table


I needed a way to restrict file access to users based on the state they live in. I have a table with user info and another table with a list of states. The users table pulls in a foreign key from the states table.

 
I needed an index view that would automatically restrict users to view only filepaths from the files table if their state corresponded to that file's state.

[controller: dealer_files_controller]
[app_controller: holding Auth Component]


function index(){
parent::beforeFilter();
     //accesses before filter in the app_controller
     $stateAllow = array('DealerFile.state_id' => $this->Auth->ser('state_id'));  
     //store the state_id of the user in the current session of the Auth Component
     $this->set('dealerFiles', $this->paginate("DealerFile", $stateAllow));
     //set only the state_id of the dealerFile if it equals the state_id of the  User and places it in the view
}

 
created [2010-11-20 17:15:32]
modified [2010-11-20 17:15:32]