Skip to content

Instantly share code, notes, and snippets.

@firecentaur
Last active December 28, 2015 23:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save firecentaur/7578713 to your computer and use it in GitHub Desktop.
Save firecentaur/7578713 to your computer and use it in GitHub Desktop.
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'id'=>'order-grid',
'columns'=>array(
array(
'header' => 'Word',
'name'=> 'Word',
'value' => $data->lemma
),
array(
'header' => 'Definition',
'value' => '"testtest"',
),
)
));
----
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$sql = 'select
words.lemma,
mepsynsets.definition,
mepsenses.wordid,
mepsynsets.synsetid
from mepsynsets
left join mepsenses on mepsynsets.synsetid = mepsenses.synsetid
left join words on mepsenses.wordid=words.wordid
where lemma=:lemma';
$synsets=Yii::app()->db->createCommand($sql);
$synsets->bindParam(":lemma",$this->searchTerm);
$dataReader = $synsets->query();
$count= $dataReader->rowCount;
$dataProvider=new CSqlDataProvider(
$sql,array(
'keyField'=>'synsetid',
'totalItemCount'=>$count,
//'totalItemCount'=>$count,
'params'=>array(
':lemma'=>$this->searchTerm,
),
'sort'=>array(
'attributes'=>array(
'definition', 'lemma','wordid','synsetid'
),
),
'pagination'=>array(
'pageSize'=>20
)
));
return $dataProvider;
}
@adilshahzad
Copy link

$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'id'=>'order-grid',
'columns'=>array(
array(
'header' => 'Word',
'name'=> 'Word',
'value' => '$data->lemma'
),
array(
'header' => 'Definition',
'value' => 'testtest',
),
)
));

@firecentaur
Copy link
Author

My controller is :
public function actionSearch()
{
if (isset($_GET["SearchSynsetsModel"]["searchTerm"])){
$searchTerm=$_GET["SearchSynsetsModel"]["searchTerm"];
$model=new SearchSynsetsModel();
$lemma =Lemmatizer::lemmatize($searchTerm);
$model->searchTerm=$lemma;
$dataProvider = $model->search();
$model = new SearchSynsetsModel();
$model->searchTerm=$searchTerm;
$this->render('searchResultsView',
array(
'dataProvider'=>$dataProvider,
'model'=>$model,

            ));
    }

@adilshahzad
Copy link

$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->search(),
'id'=>'order-grid',
'columns'=>array(
array(
'header' => 'Word',
'name'=> 'Word',
'value' => $data->lemma
),
array(
'header' => 'Definition',
'value' => '"testtest"',
),
)
));

@firecentaur
Copy link
Author

Turns out I didnt need to try to provide a value for those fields, I just needed to write in their names and gridview took care of the rest - thanks a mill for all your help - please add me on LinkedIn
http://www.linkedin.com/pub/paul-preibisch/4/130/a64

Ill give you a nice endorsement

$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->search(),
'id'=>'order-grid',
'columns' =>array(
array(
'name'=>'lemma',
"header"=>"Word"
),
'definition',
'wordid',
'synsetid',
array(
'header'=>"Action",
'name'=>'action'
)

            )


));

@adilshahzad
Copy link

$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->search(),
'id'=>'order-grid',
'columns' =>array(
array(
'name'=>'Word',
'htmlOptions'=>array('style'=>'text-align:center; width:100px'),
'value'=>'$data->lemma',
),
'definition',
'wordid',
'synsetid',
array(
'header'=>"Action",
'name'=>'action'
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment