Yii Framework Forum: CGridView relational field not required - Yii Framework Forum

Jump to content

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

CGridView relational field not required Rate Topic: -----

#1 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 536
  • Joined: 11-August 09
  • Location:Argentina

Posted 12 August 2010 - 07:17 AM

Hi @all

i,m go from php 5.2 to 5.3
and i get a error when use CGridView , relational fields and this fileds is not required

the field not required is "id_sector"

the error

Quote


PHP Error

Descripción
Trying to get property of non-object


Archivo Fuente:
/var/www/sistemas/framework/base/CComponent.php(620) : eval()'d code(1)

No hay código fuente disponible.

my code

in the model


    public function relations()
    {
        return array(

                'sector' => array(self::BELONGS_TO, 'Sector', 'id_sector'),
        );
    }



    public function search()
    {

  $sort = new CSort();
  
  $sort->attributes = array(
   'id_ticket',

   'name'=>array(
      'asc'=>'t.name',
      'desc'=>'t.name desc',
    ),

   'id_sector'=>array(
      'asc'=>'sector.descripcion',
      'desc'=>'sector.descripcion desc',
    ),
   'timestamp'=>array(
      'asc'=>'t.timestamp',
      'desc'=>'t.timestamp desc',
    ),

  );


        $criteria=new CDbCriteria;
                $criteria->addCondition('t.borrado=0');

                $sort->defaultOrder = 't.timestamp DESC';

                $criteria->with=array('sector');
        $criteria->compare('t.id_ticket',$this->id_ticket);



        $criteria->compare('t.name',$this->name,true);

        $criteria->compare('sector.descripcion',$this->id_sector,true);


        $criteria->compare('t.timestamp',$this->timestamp,true);

        return new CActiveDataProvider('Ticket', array(
            'criteria'=>$criteria,
                        'sort'=>$sort,
                        
        ));
    }



in the view


<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'ticket-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
        'summaryText'=>'Mostrando {start}-{end} de {count}',
    'columns'=>array(


        'name',
                array('name'=>'id_sector','sortable'=>'true','value'=>'$data->sector->descripcion'),
        
        'timestamp',
        
        array(
            'class'=>'CButtonColumn',
        ),
    ),
)); ?>



help !

[edit]

Quote

in 5.2 work fine

the error is when id_sector is null
if the filed have a value, work fine

This post has been edited by Horacio Segura: 12 August 2010 - 07:26 AM

KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
0

#2 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 536
  • Joined: 11-August 09
  • Location:Argentina

Posted 12 August 2010 - 08:15 AM

I'm not sure I "solved" the problem
but it works!!

    public function actionAdmin()
    {
        $model=new Ticket('search');
        if(isset($_GET['Ticket']))
            $model->attributes=$_GET['Ticket'];

        error_reporting(E_ALL ^ E_NOTICE);

                $this->render('admin',array(
            'model'=>$model,
        ));
    }


KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
0

#3 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 12 August 2010 - 08:28 AM

You have an error because if you try to access a property on a non-object you get a notice.

Is not a question of version of php, just a question of errorReporting.

I can advice you to use E_ALL and correct your code in the view:

 array('name'=>'id_sector','sortable'=>'true','value'=>'($data->sector)?$data->sector->descripcion:"no sector"'),


1

#4 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 536
  • Joined: 11-August 09
  • Location:Argentina

Posted 12 August 2010 - 08:39 AM

thanks !!!!

work fine!


View Postzaccaria, on 12 August 2010 - 08:28 AM, said:

You have an error because if you try to access a property on a non-object you get a notice.

Is not a question of version of php, just a question of errorReporting.

I can advice you to use E_ALL and correct your code in the view:

 array('name'=>'id_sector','sortable'=>'true','value'=>'($data->sector)?$data->sector->descripcion:"no sector"'),



KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
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