0

I tried defining the dataprovider for CGridView in yii but am getting this

error 500: Trying to get property of non-object

the following are my model and view/admin.php code snippets

model.php:

public function search2()
{
    $sql='select family_tree.tree_creator_id, C.user_fullname, 
    family_tree.tree_user1_id, A.user_fullname,
    family_tree.tree_user2_id,B.user_fullname,
    family_tree.tree_type, family_tree.tree_type_name
    from family_tree
    join user A on A.user_id=family_tree.tree_user1_id
    join user B on B.user_id=family_tree.tree_user2_id
    join user C on C.user_id=family_tree.tree_creator_id
    ';

    if($this->tree_creator_id!=NULL)
    {
        $sql.="where family_tree.tree_creator_id='$this->tree_creator_id'";
    }

    $a= Yii::app()->db->createCommand($sql)
    ->queryAll();

    return new CArrayDataProvider($a, array(
        'id'=>'family-tree',
        'keyField'=>'tree_id'));
}

admin.php:

    <?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">

    <?php $this->renderPartial('_search',array(
    'model'=>$model,
    )); ?>
</div><!-- search-form -->

    <?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'family-tree-grid',
    'dataProvider'=>$model->search2(),

    'columns'=>array(
        'tree_id',
        'tree_creator_id',
        'tree_user1_id',
        'tree_user2_id',
        'tree_type',
        'tree_type_name',

        /*'tree_grey_flag',*/

        array(
            'class'=>'CButtonColumn',
        ),
    ),
)); ?>

any help would be appreciated, thanks!

Criesto
  • 1,985
  • 4
  • 32
  • 41

1 Answers1

0

In your select i don't see the

 'tree_id', 

and could by useful a notation avoiding fields ambiguity like

 tableName.columnName as uniqueFieldName 

and in gridview refer to uniqueFieldName

I Hope this could be useful

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • tree_id in just an auto increment value used to retrieve the whole row of data by index. what i want to do is do multiple joins to retrieve user_fullname for instances of tree_user1_id, tree_user2_id and tree_creator_id. the database schema is something like this: **user** : user_id **|** user_fullname ; **family_tree** : tree_creator_id **|** tree_user1_id **|** tree_user2_id **|** – Sebrinar Yaslana Sep 22 '15 at 00:24