0
I’m listing neighborhoods, when I select instead of taking the list value, the json_encode
is returning to her position. ex:
-BARRIO I -WARD II
If I select the "NEIGHBORHOOD II", it will return me: "1"
"0"-QUARTER I "1"-QUARTER II ...
Follow the code:
public function pegarBairros ($cidade = null) {
$this->layout = 'json';
$result = array();
if (in_array($_REQUEST['cidade'], array_keys($this->cidade))) {
$this->loadModel('Bairro');
$bairros = $this->Bairro->find('list', array('fields' => array('id','bairro'), 'conditions' => array('cidade' => $this->cidade[$_REQUEST['cidade']]),'group' => 'bairro'));
sort($bairros);
foreach ($bairros as $bairro)
if (!empty($bairro)){
$result[] = $bairro;
$arr = $result;
json_encode($arr);
}
} else $result[] = 'error';
$this->set('data', $arr);
}
for me to show, I use so:
echo $this->Form->input('bairro', array('label' => 'Bairro', 'empty' => 'Selecione o Bairro', 'options' => array() ));
What’s wrong with the code?
E How to sort the neighborhoods in this line in Cakephp?
$bairros = $this->Bairro->find('list',
array('fields' => array('id','bairro'),
'conditions' => array('cidade' => $this->cidade[$_REQUEST['cidade']])
)
);
Furlan, in its original function, try to rotate a
die(var_dump($bairros));
just below its function and post the result.– gmsantos
You have taken the context of the whole question, and the answers have become meaningless. Please go back and add your doubt just below. Your question may be useful to other people.
– marcusagm