components/SearchResult.php:
class SearchResult extends CActiveRecordBehavior {
public $matching_field_values = array();
}controllers/SearchController.php:
public function actionResults() {
/* Snipped generation of search criteria */
$values = Field_Value::model()->with('owner', 'field')->findAll($dbCriteria);
$results = array();
foreach($values as $v) {
$v->owner->attachBehavior('match', 'application.components.SearchResult');
$v->owner->matching_field_values[] = $v;
if(!in_array($v->owner, $results)) { $results[] = $v->owner; }
}
$this->render('basicresults', array('results'=>$results));
}Field_Value->owner is specified by a BELONGS_TO relation to a User model.
views/search/basicresults.php:
<?php foreach($results as $r): ?> <h3><?php echo CHtml::encode($r->name); ?></h3> <?php foreach($r->matching_field_values as $v): ?> <u><?php echo CHtml::encode($v->field->label); ?></u>: <?php echo CHtml::encode($v->value); ?><br /> <?php endforeach; ?> <?php endforeach; ?>
Currently, the Users name is printed, but none of the Field_Values that were matched are displayed.
The strange thing is: When I print_r($r->matching_field_values), I get an empty array(), indicating the behavior is at least attached (otherwise it would be NULL, right?). However, When I test for $r->canGetProperty('matching_field_values'), it returns false.
Who can help me get this working?

Help















