Problem With Csqdataprovider And Gridview

Hi Experts,

I’m stuggling with using CSQLDataProvider

Here is my model function





class PersonJunior extends BasePersonJunior {


    public $ARlabel;

    public $ARresult;

    //Also Set Validation Rules

    ...

    //Something working without csqldataprovider

    public function getInterruptions($status) {

        $criteria = new CDbCriteria;


        $criteria->select = array('assignment_interruption.interruptee AS ARlabel', 'COUNT(assignment_interruption.id) AS ARresult');

        $criteria->with = array(

            'assignments', 'assignments.interruption',

        );

        $criteria->join = "RIGHT JOIN assignment_interruption ON t.id = assignment_interruption.id ";

        if (count($status)) {

            $criteria->condition = $this->buildStatusString($status);

        }

        $criteria->group = 'ARlabel';

        return new CActiveDataProvider($this, array(

            'criteria' => $criteria,

                ));

    }


    //Offending function

   public function getExtensions($status) {

        /*


          $statusstring = '';

          if (count($status)) {

          $statusstring = 'AND ' . $this->buildStatusString($status);

         */




        $sql = "SELECT 'Extended' AS ARlabel, count( assignment.id ) AS ARresult FROM person_junior

                INNER JOIN assignment ON person_junior.id = assignment.junior

                WHERE stop_date_extended IS NOT NULL";

        /* $sql .= "UNION

          SELECT 'Extended' AS ARlabel, count( assignment.id ) AS ARresult FROM person_junior

          INNER JOIN assignment ON person_junior.id = assignment.junior

          WHERE stop_date_extended IS NOT NULL";

         */


        return new CSqlDataProvider($sql);

    }




}

Controller function




    public function actionAdmin() {

        $model = new PersonJunior('search');

        $model->unsetAttributes();

        $x=array();

        if (isset($_GET['PersonJunior'])){

            $model->setAttributes($_GET['PersonJunior']);

            $x = $model->getAttribute('dstatus');

            

        }

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

            'model' => $model, 'dstatus' => $x

        ));

    }




And gridview call




<?php $this->widget('bootstrap.widgets.TbGridView',array(

    'id'=>'person-junior-grid',

    'dataProvider'=>$model->getExtensions($dstatus),

    'filter'=>$model,

    'columns'=>array(

        'ARlabel','ARresult',

          

        

               array(

            'class'=>'bootstrap.widgets.TbButtonColumn',

        ),

    ),

)); ?> 




If I replace any ‘dataProvider’=>$model->getExtensions($dstatus) with ones such the example specify based on the normal CActiveDataProvider all is well.

The SQL instruction works fine in php my admin (both commented and non-commented out)

What am I doing wrong,

This has been hindering me for hours

The error:

Trying to get property of non-object:

This might be helpful:


#1 	

–

 /var/www/html/juniordb/protected/extensions/bootstrap/widgets/TbButtonColumn.php(60): CComponent->evaluateExpression("Yii::app()->controller->createUrl("view",array("id"=>$data->prim...", array("data" => array("ARlabel" => "Extended", "ARresult" => "178"), "row" => 0))


55     {

56         if (isset($button['visible']) && !$this->evaluateExpression($button['visible'], array('row'=>$row, 'data'=>$data)))

57             return;

58 

59         $label = isset($button['label']) ? $button['label'] : $id;

60         $url = isset($button['url']) ? $this->evaluateExpression($button['url'], array('data'=>$data, 'row'=>$row)) : '#';

61         $options = isset($button['options']) ? $button['options'] : array();

62 

63         if (!isset($options['title']))

64             $options['title'] = $label;

65 



please help!!!

THANKS GUYS!

Probem soved

had to search for an extra id and remove grid buttons, which was suitable in the given use case

thanks yii community on MIRC