2013-07-09 29 views
0

嗨,我要選擇以下從table.i嘗試,但下劃線的值,它不工作.... enter image description hereYii的標準問題,與外國表中選擇值

$criteria = new CDbCriteria;  

    $criteria->select = array('description', 'id','rate','item_unit_id'); 
    $criteria->with=array("item_unit","color"); 
    $criteria->together = true; 
    $criteria->addSearchCondition("description", $_GET['query']); 

    $criteria->limit = $this->limit; 

    $items = Item::model()->findAll($criteria); 
    $suggestions = array(); 
    $x=0; 
    foreach ($items as $c) { 
     $suggestions[$x]['value'] = $c->description; 
     $suggestions[$x]['id'] = $c->id; 
     $suggestions[$x]['rate'] = $c->rate; 
     $suggestions[$x]['unit'] = $c->item_unit->name; 
     $x++; 
    } 

回答

3

好吧,如果你將」讀過你會知道的文檔,而是因爲你沒有,你不:)

然而,這可能會幫助您:

$criteria->select = 't.id, t.description, t.rate, t.code, color.name, item_unit.name'; 
$criteria->with = array(
    "item_unit" => array(
     'together' => true, 
     'joinType' => 'INNER JOIN' 
    ), 
    "color" => array(
     'together' => true, 
     'joinType' => 'INNER JOIN', 
    ) 
); 

$criteria->addSearchCondition("t.description", $_GET['query']); 
$criteria->limit = $this->limit; 

$items = Item::model()->findAll($criteria); 
+0

感謝朋友...我會試試這個...... –

+0

bro它給出這個錯誤...關係「item_unit」沒有在活動記錄類「Item」中定義。 –

+1

好,定義關係,這不是明顯嗎?或者更好的是,開始閱讀Yii用戶指南,你還沒有準備好使用Yii。 – Twisted1919