简体   繁体   English

选择在Yii CDbCriteria中不起作用

[英]Select not working in Yii CDbCriteria

I have two related table and I have to display data from both trough a join query. 我有两个相关的表,并且必须通过联接查询显示两个表中的数据。 I have this GridView that is "working" when i have to do the search, so that's mean if I have to search into a field from the joined table, it works and shows the right result, but I am not able to show all the column from both table. 我有这个GridView ,当我必须执行搜索时“正在工作”,因此,这意味着如果我必须从联接表中搜索一个字段,它可以工作并显示正确的结果,但我无法显示所有两个表中的列。

Here is the error: 这是错误:

CDbCommand failed to execute the SQL statement: SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table 'pratiche'. CDbCommand无法执行SQL语句:SQLSTATE [42S02]:未找到基表或视图:1051未知表'pratiche'。 The SQL statement executed was: SELECT pratiche.* FROM pratiche t LEFT JOIN clienti ON id_cliente = clienti.id LIMIT 10 执行的SQL语句为:SELECT pratiche。* FROM pratiche t LEFT JOIN clienti ON id_cliente = clienti.id LIMIT 10

As you can see there is t after pratiche , so it fail the query. 如您所见,在pratiche之后没有t ,因此它使查询失败。 What's the problem? 有什么问题?

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,
    ));
}

SOLVED! 解决了! Wrong way to set the 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