Hi,
I’m just building my very first Yii application.
I have 3 tables:
user
uid <–PK
imie
nazwisko
zainteresowania
zid <–PK
nazwa
user_zainteresowania
uid <-- FK to user
zid <-- FK to zainteresowania
So we have many to many relation here, it is of course defined in models:
User model:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'zainteresowania' => array(self::MANY_MANY, 'Zainteresowania', 'user_zainteresowania(uid,zid)'),
);
Zainteresowania model:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'user' => array(self::MANY_MANY, 'User', 'user_zainteresowania(zid,uid)'),
);
}
And CgridView:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'uid',
'imie',
'nazwisko',
array(
'name'=>'zainteresowania',
'value'=>'$data->zainteresowania->nazwa',
),
array(
'class'=>'CButtonColumn',
),
),
)); ?>
Search function i User model:
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('t.uid',$this->uid);
//true na koncu oznacza, ze mozna filtrowac czesciami nazw
$criteria->compare('t.imie',$this->imie,true);
$criteria->compare('t.nazwisko',$this->nazwisko,true);
//load the related table at the same time:
$criteria->with=array('zainteresowania');
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}
And I receive Error: htmlspecialchars() expects parameter 1 to be string, array given
What should I change to be able to view in CGridView data from both tables (user and zainteresowania) ?
This topic is widely discussed over the net, but I haven’t found satysfying solution…
Regards.