I hope I'm doing very well, I'm learning cakephp 3 and I'm stuck. I have problems adding a custom attribute to each selector option and a custom class as well.
What I have right now is this:
Controller
// Insercion datos EspMunicipios
$this->loadModel('EspMunicipios');
$camping = $this->EspMunicipios->CampingInfos->newEntity();
// EspMunicipios
$ResultMunicipio = $this->EspMunicipios->find('all',
array(
'fields'=>array('id','municipio','id_provincia'),
'order' => ['EspMunicipios.municipio' => 'ASC']
));
$row_options_municipios = array();
$row_data_id_provincia = array();
foreach($ResultMunicipio->toArray() as $key => $val){
$row_options_municipios[$val['id']] = $val['municipio'];
}
$this->set('ResultMunicipio', $row_options_municipios);
// Fin EspMunicipios
View
echo $this->Form->select('id_municipio',$ResultMunicipio);
edit (add result):
<option value="6537">Ababuj</option>
And what I want to do is this (I've done this without the framework):
<select class="form-control" id="municipio" name="municipio" disabled="disabled">
<?php
echo '<option value="0" selected="selected">Seleccione un municipio</option>';
while ($line = $R_Municipios->fetch_row()) {
echo "<option class='hide' id='option_municipio' prov=".$line[2]." value=".$line[0].">";
echo $line[1];
echo "</option>";
}
// Liberar resultados
$R_Municipios->free();
?>
</select>
Result
<option class="hide" id='option_municipio' prov="3" value="6537" >Ababuj</option>
I would like to make a custom attribute "prov" or "data-prov", also assign the "hide" class to each option and custom id. I do this because all the results will be controlled by jquery, changing the hide class to show.
I would like to know how to add custom attributes and custom classes to each selector option, thank you very much.