Reputation: 11
I would like to know how to add a drop down list for "access control" with value "staff" and "Admin". This is my add function in employee controller
public function add() {
if ($this->request->is('post')) {
$this->Employee->create();
if ($this->Employee->save($this->request->data)) {
$this->Session->setFlash(__('The employee has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The employee could not be saved. Please, try again.'));
}
}
}
This is the add view code:
<div class="employees form">
<?php echo $this->Form->create('Employee'); ?>
<fieldset>
<legend><?php echo __('Add Employee Details'); ?></legend>
<?php
echo $this->Form->input('employee_name');
echo $this->Form->input('date_hired', array('dateFormat' => 'DMY','minYear'=>date('Y')-100, 'maxYear'=>date('Y')+100));
echo $this->Form->input('employee_phone_number');
echo $this->Form->input('employee_email');
echo $this->Form->input('employee_address');
echo $this->Form->input('employee_dob', array('dateFormat' => 'DMY','minYear'=>date('Y')-100, 'maxYear'=>date('Y')+100));
echo $this->Form->input('access_level');
echo $this->Form->input('employee_username');
echo $this->Form->input('employee_pw');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
Upvotes: 0
Views: 4449
Reputation: 465
To add a drop down list for access control
with value staff
and Admin
.
add this in your employee controller
$customers = $this->Employee->modelname->find('list');
$this->set(compact('customers'));
and in view.ctp
echo $this->Form->input('access_level');
Upvotes: 2
Reputation: 4526
If you are getting access_level data from database then-
echo $this->Form->input('access_level', array('options' => array('admin' => 'Admin', 'staff' => 'Ataff')));
Upvotes: 1