I have a custom attribute/variable in my model. I set the value for it in afterFind().
class Asd extends CActiveRecord
public $showInGridView = false;
public function afterFind()
if(in_array($this->id, array(4, 8, 15, 16, 23, 42)))
$this->showInGridView = true;
How do I make a CActiveDataProvider that only gives me the results that have showInGridView attribute set to true?
Can this be done without first looping over all results and eliminating the ones we don’t want? If not, then how do I do I go about kicking the unwanted objects out?
$asds = Asd::model()->findAll();
foreach($asds as $asd)
if(!$asd->showInGridView) unset(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />); // how do I remove it? or what... I don't even... how does this work again <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />?
No, well, that’s not actually the condition. I evaluate the value of the custom variable with more complex functions actually. I even look into the Log which is another table on the database etc… I can’t just make sql of it. My bad for making a bad example, but let’s just say the custom variable can’t be determined before fetching the stuff, hence it’s value is set in afterFind. But my question is if I can filter by it in a GridView without manually looping through all the results, filtering out the ones I don’t want and passing the reminder off to a dataprovider. Seems like the wrong way of doing things.
Right now I do it like this and it doesn’t feel efficient: