I’m trying to join a relational table profiles at the CSqlDataProvider, but it’s not working property.
How can I have access to profiles.id in the view?
Controller.php:
$sql = "SELECT `events`.`id`
FROM events
LEFT OUTER JOIN `profiles` ON (`events`.`profile_id`=`profiles`.`id`)";
$dataProvider=new CSqlDataProvider($sql);
View.php:
<?php $this->widget('bootstrap.widgets.TbGridView',array(
'type'=>'striped bordered condensed',
'id'=>'events-grid',
'dataProvider'=>$dataProvider,
'columns'=>array(
'profiles.id', // Problem here, always returns NULL.
'events.id',
),
)); ?>
First ofcourse you need to
selectthe other field as already mentioned in Phillipe’s answer :It’ll be better to give
profiles.idan alias because the both the column names areid:Then in the grid you can access these columns as: