Yii - CGridView 1-to-N Display issues -


i've started yii month ago , finding intuitive, yet somehow confusing regarding widgets.

in app i'm developing, although use active record, cannot use it's relations using myisam (and cannot changed) , has no support foreign keys.

my issue have cgridview , want add custom data it, having issues.

it 1-to-many relationship fk in right model, said, cannot use ar's magic.

i have this, applications model , profile model. profile model has application fk.

i got function when i'm rendering cgrid can fetch name of each application instead of *id_app*.

public function appname($id){     $app= yii::app()->db->createcommand()         ->select('name')         ->from('tbl_aplications a')         ->where('a.id=:id_app', array(':id_app'=>$id))         ->queryrow();      return $app; } 

in auto-generated templates, in profile admin.php view, got:

$this->widget('zii.widgets.grid.cgridview', array(     'id'=>'profile-application-grid',     'dataprovider'=>$model->search(), //maybe issue criteria? 'as-is' after template generation     'filter'=>$model,     'columns'=>array(         'id',         'name',                 array(                     'name'=>'id_app',                     'header'=>'aplication', 

and here issue, i've tried (and sorts of variations):

'value' => 'profileapplication::model()->appname($data->id_app)', 'value' => 'profileapplication::model()->appname(id_app)', 'value' => 'profileapplication::model()->appname("id_app")', 

and null result because passing actual string instead of each row's value. if pass direct id function's query, returns correct value, ->where('a.id=:id_app', array(':id_app'=>3))

is search criteria needs altered? i've found similar questions of them use ar such profile->application or along lines , said, cannot use due myisam restrictions.

any tips appreciated newcomer, or links solution regarding similar issue .

to use value attribute such need, prplhaz4 said, data provider. then, $data variable has magic, , must used in string because eval()'ed behind scenes. here example of trying do:

<?php $this->widget('zii.widgets.grid.cgridview', array(     'id'=>'item-grid',     'dataprovider'=>$model->search(),     'columns'=>array(         array(             'name' => 'id',             'header' => 'item id',          ),         array(             'name' => 'category_search',             'header' => 'category',             'value' => '$data->category->name',         ),     ), )); ?> 

that grabs name attribute of related item category model. in relations() function of item model:

return array(     'category'=>array(self::belongs_to, 'itemcategory', 'category_id'), ); 

and in relations() function of item category model:

return array(     'items'=>array(self::has_many, 'item', 'category_id'), ); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -