Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Filter By Custom Model Attributes

$
0
0
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(???); // how do I remove it? or what... I don't even... how does this work again :)?

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>