Skip to content

Instantly share code, notes, and snippets.

@dmsysop
Last active November 5, 2015 16:55
Show Gist options
  • Save dmsysop/8f347fb7ed561387317c to your computer and use it in GitHub Desktop.
Save dmsysop/8f347fb7ed561387317c to your computer and use it in GitHub Desktop.
//No Controller
$conditions = array('AnunciantesCategoria.anunciante_id' => $id);
$fields = array('AnunciantesCategoria.id');
$AnunciantesCategoriaId = $this->AnunciantesCategoria->find('all', compact('conditions', 'fields'));
foreach ($AnunciantesCategoriaId as $k => $v) {
$selecionadas[] = $v['AnunciantesCategoria']['id'];
}
$fields = array('Categoria.id', 'Categoria.nome');
$categorias = $this->Anunciante->Categoria->find('list', compact('fields'));
$this->set(compact('categorias', 'selecionadas'));
//Na view
echo $this->Form->input('categoria_id', array(
'between' => '<div class="col-sm-7">',
'multiple' => 'multiple',
'id' => 'multiselect',
'selected' => $selecionadas,
'class' => 'gui-input',
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment