Yii Framework Forum: Strange behavior of $criteria->order - Yii Framework Forum

Jump to content

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

Strange behavior of $criteria->order Rate Topic: -----

#1 User is offline   Max Cfasman 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 07-September 09

Posted 24 August 2010 - 10:29 AM

Hi guys,

Have a question about CdbCriteria. I am trying to execute this query:


select * from logs_smtpserver where message LIKE 'Connection from%' GROUP BY message,class,priority,log_date ORDER BY log_date DESC;

Of course I use Yii Active record, it looks like this:

$name = 'Connection from';
                
$criteria=new CDbCriteria;
$criteria->condition = "message LIKE :name";
$criteria->params = array(":name"=>"$name%");
$criteria->group = 'message,class,log_date,priority';
$criteria->order = 'log_date DESC';

$pages=new CPagination(logs::model()->count($criteria));
$pages->pageSize=self::PAGE_SIZE;
$pages->applyLimit($criteria);
                
$models=logs::model()->findAll($criteria);



It seems it's working, Yii produces this query(found it in the application logs):

2010/08/23 13:23:50 [trace] [system.db.CDbCommand] Querying SQL: SELECT * FROM "logs_smtpserver" WHERE message LIKE :name GROUP BY message,class,log_date,priority

ORDER BY log_date DESC LIMIT 35. Bind with parameter :name='Connection from%'

But problem is it seems that CPagination is getting broken after this query and not showing me any pagination:

I've tried to print out $criteria variable,like this print_r($criteria);

And it looks like this:

CDbCriteria Object ( [select] => * [distinct] => [condition] => message LIKE :name [params] => Array ( [:name] => Connection from% ) [limit] => -1 [offset] => -1

[order] => log_date DESC [group] => message,class,log_date,priority [join] => [having] => )

limit and offset are -1 which is weird.

Any help,maybe it is a bug,or something wrong with my query,but the only thing which I am trying is to use ORDER BY.

I use PotgreSQL as a DB backend.
0

#2 User is offline   binkabir 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 193
  • Joined: 25-July 10
  • Location:Abuja,Nigeria

Posted 27 August 2010 - 05:19 AM

can you just simply use any of the following widgets from zii
CGridView or CListView then customize the property, but firstly use the CActiveDataProvider class with your criteria class options to fetch the record from the Db. (this have a pagination options that will aid in automatically creating the pagination of all the retrieved data)
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