Yii Framework Forum: Problem With Csqdataprovider And Gridview - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Problem With Csqdataprovider And Gridview Rate Topic: -----

#1 User is offline   Jeffrico El Exotico 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 16-January 13

Posted 18 February 2013 - 04:49 PM

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!
0

#2 User is offline   Jeffrico El Exotico 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 16-January 13

Posted 18 February 2013 - 06:34 PM

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users