Приветствую!
Возникла такая проблема, т.к. совсем новичок.
Есть две сущности, связанные друг с другом отношением "один-ко-многим" с помощью третьей сущности.
Связать их удалось, но не получается вывести в представлении в одной таблице. Например нужно вывести каталог фильмов и к каждому фильму привязать список актёров, игравших в нём. Отдельно могу получить таблицу с фильмами и отдельно список актёров и вывести их через контроллер, ну всё как в разделе "Реляционная Active Record".
Вот модель:
<?php
/**
* This is the model class for table "films".
*
* The followings are the available columns in table 'films':
* @property integer $id
* @property string $title
* @property integer $year
* @property string $director
* @property string $description
* @property string $poster
* @property double $rate
*/
class Films extends CActiveRecord
{
public $dir;
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'films';
}
public function relations()
{
return array(
'actors'=>array(self::MANY_MANY, 'actors', 'chain(id_films, id_actors)'),
);
}
public function attributeLabels()
{
return array(
'id' => 'Номер',
'title' => 'Название',
'year' => 'Год',
'director' => 'Режисёр',
'description' => 'Описание',
'poster' => 'Обложка',
'rate' => 'Рейтинг',
'actors' => 'Актёры',
);
}
}
И представление, сгенеринное с помощью CRUD:
<?php
$this->breadcrumbs=array(
'Films'=>array('index'),
'Manage',
);
$this->menu=array(
array('label'=>'List Films', 'url'=>array('index')),
array('label'=>'Create Films', 'url'=>array('create')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('films-grid', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1>Manage Films</h1>
<p>
You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'films-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'title',
'year',
'director',
'description',
'poster',
'rate',
),
)); ?>