Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, Yii is quite handy for this kind of feature, but you should first rewrite your model to use relations.</p> <p>In your model :</p> <pre><code>// this attribute will be used in search function private $_authorName; public function rules() { return array ( ..... array('authorName', 'safe', 'on'=&gt;'search'), ..... ); } public function relations() { return array( ..... 'author' =&gt; array(self::BELONGS_TO, 'TUsers', 'fk_authorid'), ..... ); } // authorName getter public function getAuthorName() { if ($this-&gt;scenario=='search') return $this-&gt;_authorName; return $this-&gt;fk_authorid.', '.$this-&gt;author-&gt;ch_completeName; } // authorName setter public function setAuthorName($authorName) { $this-&gt;_authorName = $authorName; } public function search() { $criteria=new CDbCriteria; ..... // search author name ? if ($this-&gt;authorName!==null) { $criteria-&gt;with = array('author'); $criteria-&gt;compare('author.ch_completeName', $this-&gt;authorName, true); } ..... return new CActiveDataProvider($this, array( 'criteria'=&gt;$criteria, )); } </code></pre> <p>And in your CGridView, you should simply define your column like this :</p> <pre><code>array( 'name'=&gt;'authorName', 'htmlOptions'=&gt;array('width'=&gt;'16%'), ), </code></pre> <p>And you should read this : <a href="http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/" rel="nofollow">http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload