Reputation: 423
if(isset($id)){
$groups=$this->User->findByuser_group_id($id);
$this->set('groups', $groups);
}
This is code amn using to get database details from user by filtering user_group_id but here i am getting only only one value as per the user_group_id but in db am having morethen 5 users
Upvotes: 1
Views: 47
Reputation: 66208
Magic finders are sometimes useful but if you avoid them you'll find your code is easier to read, and more obvious how to modify.
To get one record:
$one = $this->User->find('first', array(
'conditions' => array(
'user_group_id' => $id
)
));
To get five records:
$many = $this->User->find('all', array(
'conditions' => array(
'user_group_id' => $id
),
'limit' => 5
));
The find method is very flexible/versatile - check the docs for more ways to use it.
Upvotes: 0
Reputation: 116
$groups=$this->User->findAllByuser_group_id($id);
$this->set('groups', $groups);
Change find to findAll
Upvotes: 3