zhong21jia 2012-01-07 11:54:49 3349次浏览 4条回复 0 0 0

控制器:

/* 查找未读信息
* @author zxl
* @version $id
*/
public function actionUnreadMessages(){  
    $model=new Sms('search');
        
    $id =  Yii::app()->user->id; 
    $criteria = new CDbCriteria();
    $criteria->condition = "receiver_id=$id  AND read_type=1";
    $criteria->order = "send_time DESC";
    $model->dbCriteria = $criteria;
    $this->render('admin',array(
        'model'=>$model,
    ));
}

视图:

<?php 
$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'sms-grid',
    'dataProvider'=>$model->search(),
    //'filter'=>$model,
    'columns'=>array(
        'id',
        'title',
        'content',
        array(
            'name' => 'poster_id',
            'value' => 'Order::model()->getUserName($data->poster_id)',
        ),
        array(
            'name' => 'receiver_id',
            'value' => 'Order::model()->getUserName($data->receiver_id)',
        ),
		'send_time',
		array(
            'header'=>'操作',
			'class'=>'CButtonColumn',
            'template'=>'{view} {delete}',
		),
	),
)); ?>

数据库: [attach]585[/attach]

问题是把 $criteria->condition = "receiver_id=$id AND read_type=1"; 中read_type的值改成0,就能找到值! 为1时数据库日志给的信息:

Querying SQL: SELECT * FROM `dbs_sms` `t` WHERE (receiver_id=2  AND
read_type=1) AND (read_type=:ycp0) ORDER BY send_time DESC LIMIT 10
in E:\wamp\www\bonusaccsys\protected\views\sms\admin.php (58)
in E:\wamp\www\bonusaccsys\protected\controllers\SmsController.php (228)
in E:\wamp\www\bonusaccsys\index.php (13)

为什么会多出一个 AND (read_type=:ycp0) 求高手解答!谢谢!

您需要登录后才可以回复。登录 | 立即注册