[ask] get value from cdbcriteria

hi all, i wanna ask something, how to get value from cdbcriteria, i want get the value add into cgridview

the code is like this in my controller :


$criteria->select='month(date) as bulan, year(date) as tahun,count(id) as id,sum(price) as price';

			$criteria->addCondition('date >= :to and date <= :from');

			$criteria->params=array(

				':to'=>$date[0],

				':from'=>$date[1],

				);

			$criteria->group='tahun,bulan';

and i want to put the value into view :


$this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'batch-report-grid',

	'dataProvider'=>$dataProvider,//$model->search(),

	'columns'=>array(

		'bulan',

		array(

			'name'=>'Jumlah Batch',

			'type'=>'raw',

			'value'=>'$data->id',

		),

		'price',

		),

));

if i add ‘bulan’ or ‘tahun’ its not work, can someone help?

thanks

can someone help me?

thanks

The criteria represents just the query criteria… you need to make the query… or in the case of CGridView the dataprovider…

sorry, i don’t understand what u say, but when i count(id) as id and i write ‘id’ again in the view is work, same too sum(price) as price. but when i want to call month and year i just can’t use as date.

this my code in controller with the data provider :


$criteria->select='month(date) as bulan, year(date) as tahun,count(id) as id,sum(price) as price';

			$criteria->addCondition('date >= :to and date <= :from');

			$criteria->params=array(

				':to'=>$date[0],

				':from'=>$date[1],

				);

			$criteria->group='tahun,bulan';

		}

		

		

		$dataProvider=new CActiveDataProvider('BatchReport',array(

			'criteria'=>$criteria,

			'pagination'=>array(

				'pageSize'=>30,

			),

		));

		

		$this->render('admin',array(

			'dataProvider'=>$dataProvider,

			'pagination'=>array(

				'pageSize'=>30,

			),

		));

OK, you have a dataprovider… it was missing in the first post and I assumed you don’t have it… sorry…

You need to add to your model




public $bulan;

public $tahun;



wher to put in? in this is right?


	public static function model($className=__CLASS__)

	{

		return parent::model($className);

		public $bulan;

		public $tahun;

	}



Outside this function like:




class YourClass extends CActiveRecord

{

   public $bulan;

   public $tahun;


   public static function model(...)

   ...

}



thanks alot mdomba, it’s work now