So I started looking at CakePHP, and I'm just doing a few test cases to see if CakePHP will cater for all my needs.
I have a custom table (Table name: roles):
id role sub_site
1 Role 1 0
2 Role 2 0
3 Role 3 0
4 Role 4 0
5 Role 1 1
In my controller (User controler) I have the following code based on all the feedback here.
$this->loadModel("roles");
$rolesList = $this->roles->find('list', array(
'conditions' => array('sub_site' => '0'),
'fields' => array('id', 'role')
));
$this->set(compact('rolesList'));
I have the following in the view
$this->Form->input('role', array('label'=>false,
'div'=>false,
'type'=>'select',
'empty'=>'-- select one --',
'options'=>$rolesList));
Yet the output looks like this:
<select name="role" required="required" id="role">
<option value="">-- select one --</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
All I want is the output as follows:
<select name="role" required="required" id="role">
<option value="">-- select one --</option>
<option value="1">Role 1</option>
<option value="2">Role 2</option>
<option value="3">Role 3</option>
<option value="4">Role 4</option>
</select>
Please indicate what is wrong here as this is suppose to be simple to just populate?
roles__id, roles.role ASroles__roleFROM roles roles WHERE sub_site = 0 rolesList(array) 11 22 33 44 CREATE TABLEroles(idint(11) NOT NULL,rolevarchar(255) NOT NULL,sub_siteint(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTOroles(id,role,sub_site) VALUES (1, 'Recruiter', 0), (2, 'Moderator', 0), (3, 'Line Manager', 0), (4, 'Admin', 0), (5, 'Super Admin', 1);keyField=> 'id',valueField=> 'role'])); <select name="role" required="required" id="role"><option value="">-- select one --</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select>