Hi all
I just wonder what the ‘select’ clause does in the criteria of a CActiveDataProvider object. As far as I know it should filter the columns for the result set, but it does not do so. When I display the result set in a CGridView all of the table columns are shown. I had to add the ‘columns’ array to my CGridView to filter the columns I wanted to show.
This is the original code in my view:
<?php
if (isset($_POST['contact_id'])) {
$id = $_POST['contact_id'];
$donationModel = new CActiveDataProvider('Donation', array(
'criteria'=>array(
'select'=>'dateOfVisit, donationType, amount, blood_type, note, project',
'condition'=>'contact_id= :id',
'params'=>array(':id' => $id)
)
));
$donationModel->getData(false);
echo '<div id="donationDetail">';
if ($donationModel->getTotalItemCount(false) > 0 ) {
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$donationModel,
));
}
echo '</div>';
}
?>
In order to show the results as I wanted I added the columns array in the CGridView:
<?php
if (isset($_POST['contact_id'])) {
$id = $_POST['contact_id'];
$donationModel = new CActiveDataProvider('Donation', array(
'criteria'=>array(
'select'=>'dateOfVisit, donationType, amount, blood_type, note, project', // Does this work? what am I missing here to filter columns?
'condition'=>'contact_id= :id',
'params'=>array(':id' => $id)
)
));
$donationModel->getData(false);
echo '<div id="donationDetail">';
if ($donationModel->getTotalItemCount(false) > 0 ) {
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$donationModel,
'columns'=>array('dateOfVisit', 'donationType', 'amount', 'blood_type', 'note', 'project'), // this should not be necessary, since I put a select in the criteria.
));
}
echo '</div>';
}
?>
I tried using string and array in the ‘select’ clause in the criteria but with the same results.
So, what’s the point of having a ‘select’ in the CActiveDataProvider criteria??