Combo does not display name of state

4

Hello. Through the bake, I created a form to include a City. However, bake when generating the form, displays the state id and not the name of it. How do I make the name appear and not the state id? If possible, I would like to change the label from Uf to State and from nom municipality to municipality.

<div class="municipios form">
<?php echo $this->Form->create('Município'); ?>
	<fieldset>
		<legend><?php echo __('Incluir Município'); ?></legend>
	<?php
		echo $this->Form->input('uf_id');
		echo $this->Form->input('nom_municipio');
	?>
	</fieldset>
<?php echo $this->Form->end(__('Enviar')); ?>
</div>

The script used to create the Ufs and Municipalities tables is:

DROP TABLE IF EXISTS 'ufs';
CREATE TABLE IF NOT EXISTS 'ufs' (
  'id' int(10) unsigned NOT NULL COMMENT 'codigo fornecido pelo IBFE',
  'nom_estado' varchar(40) DEFAULT NULL COMMENT 'nome do estado',
  'sigla' varchar(2) DEFAULT NULL COMMENT 'sigla do estado'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 PACK_KEYS=0;


DROP TABLE IF EXISTS 'municipios';
CREATE TABLE IF NOT EXISTS 'municipios' (
  'id' varchar(7) NOT NULL COMMENT 'codigo do municipio fornecido pelo IBGE',
  'uf_id' int(10) unsigned NOT NULL,
  'nom_municipio' varchar(50) NOT NULL COMMENT 'nome do municipio'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 PACK_KEYS=0;

Displayed:

    
asked by anonymous 16.12.2014 / 02:17

1 answer

1

The name of the label you can include in the second parameter, like this:

echo $this->Form->input('uf_id', array('label' => 'Estado'));
echo $this->Form->input('nom_municipio', array('label' => 'Município'));

And for the state name, in your Uf model you can set the attribute displayField " which is your default display field:

class Uf extends AppModel {
    public $displayField = 'nom_estado';
}
    
26.12.2014 / 18:31