Good morning!
I already search something thrugh the forum but I didn’t find a solution!
I’m trying to connect 2 table in one unique view.
I have 2 tables, argomento(topic) and domande(questions), both there is an id that connect the 2 table id_argomento.
I would like showing the questions connected to a topic down in the same view.
I tried whith the following code.
I insered the relation in my 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(
'id_argomento' => array(self::BELONGS_TO, 'Domande', 'id_argomento'),
);
}
Then I created a function search to print the rows(questions) connected to my topic with id_argomento
public function search01()
{
$connection=Yii::app()->db;
$sql="SELECT * FROM domande where id_argomento ='$data->id_argomento'";
$command=$connection->createCommand($sql);
$dataReader=$command->query();
$rows=$dataReader->readAll();
$ans=array();
foreach($rows as $data)
{
$ans=$data['domanda'];
}
return $ans;
}
Then in the _view of my topic I inserted the following code
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search01(),
'filter'=>$model,
'columns'=>array(
'id_argomento',
'domanda',
array('header'=>'Domanda per questo argomento','value'=>array($model,'search01')),
'id_argomento',
array('class'=>'CButtonColumn',
'template'=>'{view}'),
),
)); ?>
I don’t understand why I got this error.
Fatal error: Call to a member function getData() on a non-object in C:\xampp\htdocs\yii\framework\zii\widgets\CBaseListView.php on line 108
Please help me, I’m new with yii and php.
I hope somebody can help me.
THANKS VERY MUCH!!!!