php - Displaying attributes from another model using CGRIDVIEW -
i have 2 tables/models:
tmp1
- header
- questiontext
tmp2
- header
- part
- outof
i'm trying display columns: header, questiontext, part, outof
in single cgridview.
in tmp1 model:
public function relations() { return array( 'tmp2s' => array(self::has_many, 'tmp2', 'header'), ); }
in tmp2 model:
public function relations() { return array( 'header' => array(self::belongs_to, 'tmp1', 'header'), ); }
controller:
public function actionreviewall() { $tmp1 = new tmp1('search'); $tmp1->unsetattributes(); if(isset($_get['tmp1'])){ $model->attributes=$_get['tmp1']; } $this->render('reviewall',array( 'tmp1'=>$tmp1, )); }
view:
$this->widget('zii.widgets.grid.cgridview', array( 'id'=>'tmp-grid', 'dataprovider'=>$tmp1->search(), 'filter'=>$tmp1, 'columns'=>array( 'header', 'questiontext', array( 'name' => 'tmp2.outof', 'value' => '$data->tmp2[0].outof', 'type' => 'raw' ), ), )); ?>
error:
property "tmp1.tmp2" not defined.
any appreciated
you have sintax error:
tmp1.tmp2 = tmp1.tmp2s
the relation alias 's'. "tmp2s".
$this->widget('zii.widgets.grid.cgridview', array( 'id'=>'tmp-grid', 'dataprovider'=>$tmp1->search(), 'filter'=>$tmp1, 'columns'=>array( 'header', 'questiontext', 'tmp2s.part', 'tmp2s.outof', ), )); ?>
but trying show 'self::has_many' relationship, can't show on normal cgridview widget...
Comments
Post a Comment