Combo does not display state name

Asked

Viewed 81 times

4

Hello. Through Bake, I created a form to include a Municipality. However, Bake when generating the form, displays the status id and not its name. How do I get the name and not the State ID to appear on it? If possible, I would like to change the label from Uf to State and from nom municipio 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 Municipios 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;

Screen displayed: inserir a descrição da imagem aqui

1 answer

1

The label name you can include in the second parameter, so:

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

And for the name of the state, in its model Uf it is possible to define the attribute displayField which is your standard display field:

class Uf extends AppModel {
    public $displayField = 'nom_estado';
}
  • You’re the man, thanks...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.