如何将模型的搜索结果保存到另一个模型中? 我在视图文件中有这个
<?php
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('wsrecruitcvhead-grid', {
data: $(this).serialize()
});
return false;
});
");
?>
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php echo " | " .CHtml::link('Save Search',array('savesearchresult','r'=>'wsrecruitcvhead/savesearchresult')); ?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'wsrecruitcvhead-grid',
'dataProvider'=>$model->search(),
#'filter'=>$model,
'columns'=>array(
#'MemberShipID',
#'ResumeID',
'ResumeTitle',
'ResumeSummaryIntroduction',
'Name',
'DOB',
array(
'class' => 'CButtonColumn',
'viewButtonUrl' => 'Yii::app()->createUrl("wsrecruitcvhead/view",array("id"=>$data["ResumeID"]))',
'template'=>'{view}',
),
),
)); ?>
如何从搜索结果中获取每个放大镜图标的ID值?
我的控制器中有这个
/*
* CV advance search page
*/
public function actionAdvancecvsearch()
{
$model = new Wsrecruitcvhead('search');
$model->unsetAttributes();
if(isset($_GET['Wsrecruitcvhead']))
$model->attributes = $_GET['Wsrecruitcvhead'];
$this->render('advancecvsearch',array(
'model' => $model,
));
}
/*
* save search results
*/
public function actionSavesearchresult()
{
$model = new Wsrecruitsavedsearches;
if(isset($_POST['Wsrecruitcvhead']))
{
$model->MemberShipID = Yii::app()->user->id;
$model->ResumeID = $_POS['Wsrecruitcvhead']['id'];
$model->datesaved = new CDbCriteria(NOW());
if($model->save())
{
$this->redirect(array('savedcvsearches','r'=>'wsrecruitcvhead/savedcvsearches'));
}
else
{
$this->redirect(array('advancecvsearch','r'=>'wsrecruitcvhead/advancecvsearch'));
}
}
}
/*
* render savedcvsearches
*/
public function actionSavedcvsearches()
{
//some code stuff here
$this->render('savedcvsearches');
}
实际上我看到了一个例子,但它并没有帮助
how to save cgridview search results
答案 0 :(得分:0)
使用display:none设置新列;使用CHtml设置隐藏字段。
'columns'=>array(
array=>(
'name'=>'',
'type'=>'raw',
'value'=>"CHtml::hiddenField('resumeIds[]', $data['ResumeID'])",
'htmlOptions'=>array('class'=>'hiddenTrClass')
)
)
这个过程就像是
foreach($_POST['resumeIds'] as $id):
//Do Something
endforeach;