Good morning, I have a problem with the CListView component, MySQL shows the correct amount of expected rows in the query, however once I run it into yii, despite debugger shows the right query, CListView shows one more record, I’ve attached some images about it, showing the SQL query I got from debugger, the one I copied and pasted in MySQL workbench, showing the expected results, and the results gotten from CListView, also added the Model, View and Controller Related Code used for this component.
Any help would be greatly appreciated, thank you
Model - Usuario
public function obtenerListaAmigos($id){
$pk = $id;
$lista_amigos = new CDbCriteria;
$lista_amigos->select = 'nombre, apellido1, apellido2';
$lista_amigos->distinct = true;
$lista_amigos->join = 'INNER JOIN tbl_amigo_por_usuario ON fkUsuario = :pk';
$lista_amigos->condition = 'pkUsuario != :pk';
$lista_amigos->params = array(':pk'=>$pk);
$this->findAll($lista_amigos);
}
Model - AmigoPorUsuario
public function obtenerCantidadAmigos($id){
$cuenta = new CDbCriteria;
$cuenta->select = 'COUNT(*) as total';
$cuenta->condition = 'fkUsuario = :id';
$cuenta->params = array(':id'=>$id);
$this->find($cuenta);
}
Controller
public function actionLista(){
$id = new Usuario;
$cuenta = new AmigoPorUsuario;
$id = Usuario::model()->obtenerListaAmigos(Yii::app()->user->getState('__id'));
$cuenta = $cuenta->obtenerCantidadAmigos(Yii::app()->user->getState('__id'));
$datos = new CActiveDataProvider('Usuario', array(
'totalItemCount'=>$cuenta,
'pagination'=>array(
'pageSize'=>5,
),
)
);
$this->render('lista', array('origen_datos'=>$datos));
}
View
<?php
$this->pageTitle=Yii::app()->name . ' - Lista';
$this->breadcrumbs=array('Lista',);
?>
<h1>Lista</h1>
<p>Amigos actualmente agregados</p>
<?php
/*$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
));*/
?>
<?php
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$origen_datos,
'itemView'=>'_listar',
)
);
?>