Note that there are some explanatory texts on larger screens.

plurals
  1. POYii search from function
    primarykey
    data
    text
    <p>I have a CGridView and I want to search in it. The thing is that I have a column that is modified by a function in my model. Everything start in the search.php view that contains a cgridview that looks like this:</p> <pre><code>$this-&gt;widget('zii.widgets.grid.CGridView', array( 'id'=&gt;'grid-demande', 'summaryText'=&gt;'', 'dataProvider'=&gt;$model-&gt;search(), //'filter'=&gt;$model, 'cssFile'=&gt;Yii::app()-&gt;request-&gt;baseUrl."/css/my_gridview.css", 'columns'=&gt;array ( array( 'name'=&gt;'id_post', 'htmlOptions'=&gt;array('width'=&gt;'16%'), ), array( 'name'=&gt;'fk_authorid', 'htmlOptions'=&gt;array('width'=&gt;'16%'), 'value'=&gt;array($this,'renderNameDmd'), ), ) </code></pre> <p>As you can see the function renderNameDmd is called to render the name of the author. This function is in my model but is called from the controller:</p> <pre><code>protected function renderNameDmd($data,$row) { $model=$this-&gt;loadModelDmd($data-&gt;id_post); return $model-&gt;getChAuthor(); } </code></pre> <p>And in the model class I call:</p> <pre><code>public function getChAuthor(){ $modelUsr=TUsers::model()-&gt;findByPk($this-&gt;fk_authorid); return $this-&gt;fk_authorid.', '.$modelUsr-&gt;ch_completeName; } </code></pre> <p>Everything works fine for displaying. My main problem is that I want to search through this cgridview and I can't search with the values that are displayed. Here is my search function that is contained in my model:</p> <pre><code>public function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria=new CDbCriteria; //more criterias $criteria-&gt;compare('fk_cip',$this-&gt;fk_cip,true); return new CActiveDataProvider($this, array( 'criteria'=&gt;$criteria, )); } </code></pre> <p>For the moment, I have tried a couple of things but nothing worked so I reseted the code to what it was initialy. For now, if I search through my cgridview I can only filter with the <em>authorid</em> and not the full column format I wrote. Exemple:</p> <p>For a row that looks like this:</p> <blockquote> <p>3231, John Doe</p> </blockquote> <p>I can only search through the:</p> <blockquote> <p>3231</p> </blockquote> <hr> <p>I want to search through the row I created from the function. Thank you for your help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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