Php YII:如何在属性上显示相关的表字段?
我是YII的新人,我有个问题。。。 我有一个这样的模特Php YII:如何在属性上显示相关的表字段?,php,yii,Php,Yii,我是YII的新人,我有个问题。。。 我有一个这样的模特 Person { $id ; $name ; $address ; } Car{ $id ; $carLicenseNumber ; $person_id ; // BELONGS TO PERSON } 我有一个CJuiAutoComplete,但我不知道在需要更新时如何在字段上显示人名 $this->widget('zii.widgets.jui.CJuiAutoComplete
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为汽车实例
我尝试使用临时变量,如
$temp=$model->person->name;
然后将$temp分配给“属性”=>$temp
它工作得很好
我只是想知道如何正确地在textfield或autocomplete字段中分配相关字段 在与一些YII开发者在Live chat上聊天后,我找到了解决方案
$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'
),
));
好的,在你的表格中,除了车的详细信息外,你是否还计划为
人
(人的详细信息,如姓名、身份证、地址)取新的值,也就是说。嗯,看来你已经找到了解决方案,祝你好运。