2012-09-06 57 views
0

我是新与谊和我有一个问题... 我有一个像YII:如何在属性上显示相关的表字段?

Person { 
    $id ; 
    $name ; 
    $address ; 
} 


Car{ 
    $id ; 
    $carLicenseNumber ; 
    $person_id ; // BELONGS TO PERSON 
} 

模型我有一个CJuiAutoComplete,但我不知道如何在显示设备领域的人的名字,当需要更新

$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
    'model'=>$model, 
    'id'=>'person', 
    'name'=>'person', 

    'attribute'=> 'person->name', // I WANT THIS but no idea how to do this ... 

    'source'=>$this->createUrl('person/suggestPerson'), 
    'options'=>array(
     'delay'=>150, 
     'minLength'=>2, 
     'showAnim'=>'fold', 
     'select'=>"js:function(event, ui) { 
      $('#label').val(ui.item.label); 
      $('#temp_person_id').val(ui.item.id); 
     }" 
    ), 
    'htmlOptions'=>array(
     'size'=>'40' 
    ), 
)); 

如何在属性上显示person-> name?

注:$模式是汽车实例

我试图用临时变量像

$ TEMP = $模型 - >人 - >名称; 然后分配$温度来“属性” => $临时 它的工作好...

我只是想知道如何用正确的方法相关领域的文本字段或自动填充字段分配。

+0

确定的解决方案,在这种形式的你你打算采取新的值'person'(个人详细资料,如姓名,身份证,地址)也?,除了'汽车'的细节是。 –

+0

不...只是名字 – nightingale2k1

+0

嗯,好像你已经找到了解决方案,祝你好运。 –

回答

0

后,我做了对即时通讯一些开发商YII聊天,我发现这个

$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
    'model'=>$model->person, // change this to model->person instead of model 
    'id'=>'person_name', 
    'name'=>'person_name', 

    'attribute'=> 'name', // just name 

    'source'=>$this->createUrl('person/suggestPerson'), 
    'options'=>array(
     'delay'=>150, 
     'minLength'=>2, 
     'showAnim'=>'fold', 
     'select'=>"js:function(event, ui) { 
      $('#label').val(ui.item.label); 
      $('#temp_person_id').val(ui.item.id); 
     }" 
    ), 
    'htmlOptions'=>array(
     'size'=>'40' 
    ), 
)); 
相关问题