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 を表示するには?

注: $model は Car インスタンスです

のような一時変数を使用しようとしました

$temp = $model->person->名前; 次に、$temp を 'attribute'=>$temp に割り当てます。これはうまく機能します ...

テキストフィールドまたはオートコンプリートフィールドに関連フィールドを割り当てる適切な方法を知りたいだけです。

4

1 に答える 1

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'
    ),
));
于 2012-09-06T05:58:11.997 に答える