Newbie in need of assistance

Hi ya’ll :) I’m still getting acquainted with Yii and it’s a bit of a challenge given that I have no prior experience with frameworks and very little with object oriented programming in general. Anyhoo, here’s the first roadblock I have come across. Here’s hoping someone can provide a little guidance, maybe just a nudge in the right direction.

Using CGridView, pulling data from several models is no problem:




// some code in a model ('Company'):

$criteria=new CDbCriteria;


$criteria->compare('name',$this->name,true);

$criteria->compare('industry',$this->industry);

$criteria->with = array( 'relationship' );

// relationship is a relation with another model


$dataProvider = new CActiveDataProvider(

  get_class($this), array('criteria'=>$criteria));


// and then in the view:

$this->widget('zii.widgets.grid.CGridView', array(

  'dataProvider'=>$dataProvider,

  'columns'=>array(

     array('name'=>'id', 'visible'=>false),

     'name',

     'industry',

     'website',

     'relationship.status',

     array( 'class'=>'CButtonColumn' )

  ),

// 'filter'=>$model

));



But suppose I want to provide filters for fields from more than one model. The ‘filter’ argument only takes a CModel.

See what I mean? What would you recommend as the best way to attack this?

+1 Im also interested in the answer

There is a topic that provides some examples of using filter on individual columns here.

That’s a different issue.

I’ll reiterate: CGridView can display data from multiple models since it pulls the data from a CDataProvider. However, the filtering (i.e. searching) capability is limited to a single model.

Here’s a link to the property in question: CGridView#filter-detail

Maybe I should implement the Relationship model as something other than CActiveRecord.

Sorry, I meant to edit that last post but I guess it didn’t save it. There is a topic that I think will help point you in the right direction here. This time it actually addresses the issue of filtering with relationships.

Thanks Yoda Pop, I’ll take a look. Right now I need a break though.

As an alternative solution I made a view and a corresponding AR model. Whether or not I want to continue this route remains to be seen.