Reputation: 1536
The table Cs_grpusu specifies the areas in my office. The table Users has a foreign key to Cs_grpusu
Cs_grpusu model (cs_grpusu.php):
<?php
class CsGrpusu extends AppModel {
var $name = 'Cs_grpusu';
var $useTable = 'Cs_grpusu';
var $primaryKey = 'grpusu';
var $displayField = 'desgrp';
}
?>
Cs_grpusu controller (cs_grpusus_controller.php):
<?php
class CsGrpususController extends AppController {
var $uses = 'Cs_gprusu';
}
?>
Cs_grpusu table content:
And in my User model I set this:
var $belongsTo = array(
'Cs_grpusu' => array(
'className' => 'cs_grpusu',
'foreignKey' => 'area'
)
);
Now I'll put these areas in my User add.ctp view form:
echo $form->input('area',array('type' => 'select','options'=>$group));
Until now I think it's OK. Now the problems. If in my user controller I fill the "group" in this way:
$this->set('grupos',$this->User->Cs_grpusu->find('all'));
My select box options became strange like this (and, debugging, I get the error that I'll describe next):
Now, if I try to fill the group variable like this:
$this->set('grupos',$this->User->Cs_grpusu->find('list', array('fields'=>array('Cs_grpusu.grpusu','Cs_grpusu.desgrp'))));
No options appear in my select box and I also get the following error:
Notice (8): Undefined index: cs_grpusu [CORE\cake\libs\model\datasources\dbo\dbo_firebird.php, line 455]
CONTEXT
$results = resource
$num_fields = 2
$index = 1
$j = 0
$column = array(
"GRPUSU",
"name" => "GRPUSU",
"GRPUSU",
"alias" => "GRPUSU",
"CS_GRPUSU",
"relation" => "CS_GRPUSU",
"2",
"length" => "2",
"SMALLINT",
"type" => "SMALLINT"
)
CODE:
$column = ibase_field_info($results, $j);
if (!empty($column[2])) {
$this->map[$index++] = array(ucfirst(strtolower($this->modeltmp[strtolower($column[2])])), strtolower($column[1]));
So, what should I do to have my select box only with the options "Reception, Budget..." whithout those strange numbers, and without the undefined index error?
Thanks!!
Upvotes: 0
Views: 322