Yii Framework Forum: Csqldataprovider And Createcommand() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Csqldataprovider And Createcommand() "CDbCommand.0" not defined Rate Topic: -----

#1 User is offline   Led 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 200
  • Joined: 16-January 12

Posted 08 October 2013 - 05:06 PM

 $res = Yii::app()->db->createCommand()
                    //->select('id,title,img1')
                    ->selectDistinct('real_estate.id,title,img1')
                    ->from('real_estate')
                    ->leftJoin('SourceMessage','((real_estate.title = SourceMessage.message) or (real_estate.description = SourceMessage.message))' )
                    ->leftJoin('Message', 'SourceMessage.id = Message.id')
                    ->where('(Message.language="' . $lang . '"  And Message.translation LIKE "%' . $_POST['query'] . '%" and real_estate.activ=1)')
                    ->queryAll();
        

        $res = new  CSqlDataProvider($res,array('keyField' => 'id',
        ));


How can i solve this.

If i use ->text i also get an error
0

#2 User is offline   Argent 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 23-February 13
  • Location:Hungary

Posted 08 October 2013 - 05:38 PM

The CSqlDataProvider is support only string or CDbCommand $sql:

public void __construct(string|CDbCommand $sql, array $config=array ( ))
                        ^^^^^^^^^^^^^^^^^^^^^^


because you use the queryAll() the first $res will be an array not a CDbCommand - remove the queryAll() row or use CArrayDataProvider instead of CSqlDataProvider ;)
0

#3 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,312
  • Joined: 21-February 11
  • Location:Greece

Posted 18 March 2014 - 11:24 AM

I agree with Argent

Also If you want to understand more about it see this wiki
http://www.yiiframew...er-in-cgridview
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users