In my users/index
page I basically list every user in the users
table by doing the following:
<?php foreach ($users as $user): ?>
<tr>
<td><?= h($user->name) ?></td>
<td><?= h($user->email) ?></td>
<td><?= h($user->phone_nr) ?></td>
<td><?= h($user->role)?></td>
</tr>
<?php endforeach; ?>
User.role
field is an enum
type with two choices: 'user'
or 'admin'
.
Instead of just listing the user's role, I need to have a dropdown to be able to change it right away. So basically I need something like:
echo $this->Form->input('role', ['type' => 'select','label' => 'Role', 'options' => ['user' => 'user', 'admin' => 'admin']]);
However, it doesn't work outside of a form and the table is obviously not a form.
Any help or guidance for how to solve is much appreciated.
EDIT
As requested, I provide the code snippet that is used to save user data (if saved from a form):
public function add()
{
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
$this->Flash->success(__('The user has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The user could not be saved. Please, try again.'));
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…