Ciao a tutti,
sto cercando di impararead usare Yii. Ho iniziato lunedì
Ho il seguente problema:Devo realizzare la seguente query in AR
SELECT COUNT(*) as Totale FROM $tbl_name
where StartDate < 2010-02-01 AND StartDate >=2010-01-01 AND device_category_id=‘A’
Io ho fatto così. ho dichiarato una variabile pubblica $totale poi
Dal mio model Projects ho aggiunto la funzione searchReport1 che contiene:
$criteria1= new CDbCriteria;
$criteria1->select="device_category_id, COUNT(device_category_id) as Totale ";
$criteria1->condition= “prj_start_date < ‘2010-02-01’ AND prj_start_date >‘2010-01-01’”;
$criteria1->group ="device_category_id";
$totale = Projects::model()->findAll($criteria1);
return new CActiveDataProvider(get_class($this), array(
‘criteria’=>$criteria1, ));
nel ProjectController ho aggiunto una funzione actionReport1 che contiene
$model=new Projects(‘searchReport1’);
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Projects']))
$model->attributes=$_GET['Projects'];
$this->render('report1',array(
'model'=>$model,
Nella view ho creato un file Report1 che contiene
$this->widget(‘zii.widgets.grid.CGridView’, array(
'id'=>'projects-grid',
'dataProvider'=>$model->searchReport1(),
'filter'=>$model,
'columns'=>array(
'device_category_id',
'totale',
array(
'header' => 'Totale',
'value' => 'totale',
),
Ho usato una gridview in funzione che devo poi estendere la mia query per tutti i mesi dell’anno,ma inizialmente volevo vedere se un record me lo scriveva.
Attualmente I campi device category e totale sono vuoti
Aiuto!!!!!