Hi all,
I have this problem i cannot get the right data from CActiveDataProvider, i’m not sure if is my code or something else.
In my view
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
'hotel_nome'
),
));
?>
In my controller
public function actionSearch() {
$criteria = new CDbCriteria ();
if (! empty ( $_POST ['search_localidade'] ))
$criteria->addCondition ( 'hotel_loc=' . $_POST ['search_localidade'] );
if (! empty ( $_POST ['search_categoria'] ))
$criteria->addCondition ( 'hotel_cat=' . $_POST ['search_categoria'] );
if (! empty ( $_POST ['search_tipo'] ))
$criteria->with = array (
'rel_HoteisTipos' => array (
'condition' => 'tipo_id=' . $_POST ['search_tipo'] ) );
//$hoteis = Hoteis::model ()->findAll ( $criteria );
$dataProvider = new CActiveDataProvider ( 'Hoteis', array (
'criteria' => $criteria ) );
$this->render ( 'search', array (
'dataProvider' => $dataProvider ) );
}
The data displaying in CGridView is wrong I get 7 records and should be only 1.
Also shouldn’t this
$hoteis = Hoteis::model ()->findAll ( $criteria );
$dataProvider = new CActiveDataProvider ( 'Hoteis', array (
'criteria' => $criteria ) );
be returning the same data?, since CActiveProvider uses the findAll to fetch the data? In the first I get 1 record and in the second i get 7 records.
Another strange thing is that in the rendered grid i get the following:
"Displaying 1-7 of 1 result(s).", i guess the message is wrong.
These are db logs:
[18:17:52.959][trace][system.db.CDbCommand] Querying SQL: SELECT COUNT(DISTINCT t.hotel_id) FROM tbl_hoteis t LEFT OUTER JOIN tbl_hoteis_tipos rel_HoteisTipos ON (rel_HoteisTipos.hotel_id=t.hotel_id) WHERE (hotel_loc=1) AND (tipo_id=7)
in E:\webserver\algarve-hoteis\yii\framework\zii\widgets\CBaseListView.php (105)
in E:\webserver\algarve-hoteis\yii\framework\zii\widgets\grid\CGridView.php (220)
in E:\webserver\algarve-hoteis\protected\views\site\search.php (7)
[18:17:52.964][trace][system.db.CDbCommand] Querying SQL: SELECT t.hotel_id AS t0_c0, t.hotel_nome AS t0_c1, t.hotel_nomelink AS t0_c2, t.hotel_cat AS t0_c3, t.hotel_stars AS t0_c4, t.hotel_loc AS t0_c5, t.hotel_morada AS t0_c6, t.hotel_descrhotel AS t0_c7, t.hotel_kywrds AS t0_c8, t.hotel_short AS t0_c9, t.hotel_mascote AS t0_c10, t.hotel_cadeia AS t0_c11, t.hotel_destaque AS t0_c12, t.hotel_tiposqrt AS t0_c13, t.hotel_dscqrts AS t0_c14, t.hotel_fb AS t0_c15, t.hotel_info AS t0_c16, t.hotel_views AS t0_c17 FROM tbl_hoteis t WHERE (hotel_loc=1) LIMIT 10
in E:\webserver\algarve-hoteis\yii\framework\zii\widgets\CBaseListView.php (105)
in E:\webserver\algarve-hoteis\yii\framework\zii\widgets\grid\CGridView.php (220)
in E:\webserver\algarve-hoteis\protected\views\site\search.php (7)
[18:17:52.967][trace][system.db.CDbCommand] Querying SQL: SELECT t.hotel_id AS t0_c0, rel_HoteisTipos.hoteltipo_id AS t1_c0, rel_HoteisTipos.hotel_id AS t1_c1, rel_HoteisTipos.tipo_id AS t1_c2 FROM tbl_hoteis t LEFT OUTER JOIN tbl_hoteis_tipos rel_HoteisTipos ON (rel_HoteisTipos.hotel_id=t.hotel_id) WHERE (t.hotel_id IN (2, 3, 4, 5, 6, 7,
) AND (tipo_id=7)
in E:\webserver\algarve-hoteis\yii\framework\zii\widgets\CBaseListView.php (105)
in E:\webserver\algarve-hoteis\yii\framework\zii\widgets\grid\CGridView.php (220)
in E:\webserver\algarve-hoteis\protected\views\site\search.php (7)
Can someone please help me and tell me what i’m doing wrong.
Thanks in advance