My page displays without any debug error but then it has this at the bottom:
Fatal error: Call to a member function search() on a non-object in C:\wamp\www\YiiTest\protected\views\site\index.php on line 6
I did the following: I tried to access the project controller/model from the index site of the site controller. To do this I put the following into the site controller:
public function actionIndex() {
$model = new project('search');
if (isset($_GET['project']))
$model->attributes = $_GET['project'];
$this->render('index', array(
'model' => $model,
));
}
In the project model there is a function called search:
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('user_id',$this->user_id);
$criteria->compare('title',$this->title,true);
$criteria->compare('description',$this->description,true);
$criteria->compare('fundgoal',$this->fundgoal);
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}
The call in the index file of the site directory is like this:
<?php $this->widget(‘zii.widgets.grid.CGridView’, array(
'id'=>'project-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'title',
'description',
),
)); ?>
Everything is displayed correctly, but this error message is at the bottom of the page. Do you have any suggestions what could be causing this? Am I doing something wrong in accessing a ‘different model’ (the project model from the site directory)?
thanks
Nicolas