Hi there,
I’m a bit stuck on providing a solution for searching records in a CListView.
I’ve followed this wiki page: http://www.yiiframework.com/wiki/229/filter-search-with-clistview/
In my code I have:
LessonsController.php
public function actionIndex() {
$model = new Lessons('search');
// Clear any default values
$model->unsetAttributes();
$this->render('index',array(
'dataProvider'=>$model->search(),
'model'=>$model
));
}
Lessons.php
public function search() {
// Get the typed query string
$query = Yii::app()->request->getQuery('query');
$criteria = new CDbCriteria;
// Package Name
$criteria->compare('package_name', $this->package_name, true);
// Quantity Name
$criteria->compare('quantity_name', $this->quantity_name, true);
// Package Id
$criteria->compare('package_id', $this->package_id, true);
// Do we have a search query string?
if ( !empty($query) ) {
$criteria->with = array('instructorToken');
$criteria->compare( 'instructorToken.first_name', $query, true );
$criteria->together = true;
}
return new CActiveDataProvider(get_class($this), array(
'criteria' => $criteria,
));
}
As you can see I’m trying to use the with method to search another table for the first name. I have a relation which is as follows:
public function relations() {
return array(
'instructorToken' => array(self::BELONGS_TO, 'Users', 'instructor_token'),
);
}
I get an error that states:
Now I’m confused as that wiki page states how to do the with comparison of the related model. Also reading the documentation of the with() method says it requires the key from the relations method.
Anyone have any idea what I’m doing wrong or missing?