this is my codes:
$this->data['users'] = $this->Ion_auth->usersdata();
foreach($users as $list){
$data = array(
'id' =>$list->id,
'email' => $list->email,
'username' => $list->username,
'active' => $list->active
);
}
$this->data['userslist'] = $data;
$this->render('users/users_list','public_master');
i want to get data from Ion_auth as a model and userdata as a method then store them to $data as an array just to encrypt some of them like id before controller sent them to the view.
Here, you are overwritting $data
at each loop. So the only thing left when you assigne $this->data['userslist'] = $data;
is the $data
declared in the last iteration.
You could try the following :
$this->data['userslist'] = [];
foreach($users as $user) {
$this->data['userslist'][] = array('id' =>$user->id,
'email' => $user->email,
'username' => $user->username,
'active' => $user->active
);
}
$this->render('users/users_list','public_master');
You are overwriting your $data
variable each time round the loop. And you are not addressing the location where you put the results from the Ion call correctly in your foreach
loop.
$this->data['users'] = $this->Ion_auth->usersdata();
foreach($this->data['users'] as $list){
$data[] = array(
'id' =>$list->id,
'email' => $list->email,
'username' => $list->username,
'active' => $list->active
);
}
$this->data['userslist'] = $data;
$this->render('users/users_list','public_master');