1
得到外部表記錄這是Yii框架和我有以下表格:tbl_banner_location_type中的ListData功能
bannerLocationTypeId(PK) bannerLocationId(FK) bannerTypeId(FK)
1 1 2
2 2 5
3 1 6
現在我有bannerLocationId的值作爲輸入。即1 我希望來自不同表格的所有橫幅類型值。 我曾嘗試下面的代碼,但得到的錯誤:物業BannerLocationType $數據 - > bannerType->值」沒有定義
$data = BannerLocationType::model()->findAll('bannerLocationId=:bannerLocationId',
array(':bannerLocationId'=>(int) $_POST['bannerLocationId']));
$data = CHtml::listData($data,'bannerTypeId','$data->bannerType->value');
echo CHtml::tag('option', array('value'=>''),CHtml::encode('- - Select - -'),true);
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
我知道我能得到它的通過以下方式的價值,但我想陣列。
$obj= BannerLocationType::model()->findByPk($id);
$obj->bannerType->value;
請幫助。
你到底在問什麼?也許你正在尋找這個:http://stackoverflow.com/questions/4435886/yii-model-to-array –
我想要數組,但基於bannerTypeId,它的值應該來自BannerType模型。 – VibhaJ
給出更多信息... bannerType表的結構以及您在banner_location_type模型中的banner_location_type和banner_type表之間定義的關係 –