Speed Demon
Speed Demon

Reputation: 691

Cakephp default index action and paginator

By default the 'index' action in my EventsController (or any Controller) returns the full set of entries and I want to display only the events created by the currently logged in user (the associations are well defined and my events table has a foreign key user_id).

here is the default index action as generated from the cake bake console command:

class EventsController extends AppController {

    public function index() {
        $this->Event->recursive = 0;
        $this->set('events', $this->paginate());
    }
    ....
}

There might be something with the $this->paginate() that I don't understand, 'cause already I tried to retrieve the entries I need using $events = $this->find('all',$options) and it didn't do anything. Is there a way to specify my conditions as to which entries will be returned to the view?

Upvotes: 0

Views: 129

Answers (1)

Nunser
Nunser

Reputation: 4522

The way to set conditions to the pagination is in the docs. Basically, if you have the user id in a variable $userID and the events have a user_id column, you could do what you ask like this

$this->set('events', $this->paginate('Event', array('user_id'=>$userID)));

Upvotes: 0

Related Questions