簡體   English   中英

選擇在Yii CDbCriteria中不起作用

[英]Select not working in Yii CDbCriteria

我有兩個相關的表,並且必須通過聯接查詢顯示兩個表中的數據。 我有這個GridView ,當我必須執行搜索時“正在工作”,因此,這意味着如果我必須從聯接表中搜索一個字段,它可以工作並顯示正確的結果,但我無法顯示所有兩個表中的列。

這是錯誤:

CDbCommand無法執行SQL語句:SQLSTATE [42S02]:未找到基表或視圖:1051未知表'pratiche'。 執行的SQL語句為:SELECT pratiche。* FROM pratiche t LEFT JOIN clienti ON id_cliente = clienti.id LIMIT 10

如您所見,在pratiche之后沒有t ,因此它使查詢失敗。 有什么問題?

public function search()
{
    // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria=new CDbCriteria;

    $criteria->select = "pratiche.*,clienti.*";

    $criteria->join='LEFT JOIN clienti ON id_cliente = clienti.id';

    $criteria->compare('id_pratiche',$this->id_pratiche,true);
    //this is the fild that should be shown(from the joined table)
    $criteria->compare('codice_fiscale',$this->codice_fiscale,true);

    $criteria->select = "pratiche.*";
    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
    ));
}

解決了! 設置標准的方法錯誤:

$criteria->select=array('id_pratiche','data_creazione','stato_pratica','nome','cognome');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM