我提前搜索页面,所有字段都声明为搜索变量。 我在会话中持有所有变量。
我想知道的是点击提交视图页面字段将保存到会话变量中。所以在网格分页和使用会话变量排序时,它将加载数据。
但是我想在点击预先搜索页面的链接时清除会话?怎么做?
public function actionAdvance_search()
{
$modelAdvSearchFinder = new AdvSearchFinder;
print_r($_GET);
if(isset($_POST) && isset($_POST['AdvSearchFinder']['submit']))
{
$this->clearAdvSearchSessionVar();
Yii::app()->session['id'] = ( $_POST['AdvSearchFinder']['id'])? Yii::app()->session['id'] = $_POST['AdvSearchFinder']['id']:"";
Yii::app()->session['name'] = ( $_POST['AdvSearchFinder']['name'])? Yii::app()->session['name'] = $_POST['AdvSearchFinder']['name']:"";
Yii::app()->session['age'] = ( $_POST['AdvSearchFinder']['age'])?Yii::app()->session['age'] = $_POST['AdvSearchFinder']['age']:"";
Yii::app()->session['class'] = ( $_POST['AdvSearchFinder']['class'])? Yii::app()->session['class'] = $_POST['AdvSearchFinder']['class']:"";
Yii::app()->session['section'] = ( $_POST['AdvSearchFinder']['section'])? Yii::app()->session['section'] = $_POST['AdvSearchFinder']['section']:"";
Yii::app()->session['Email'] = ( $_POST['AdvSearchFinder']['Email'])? Yii::app()->session['Email'] = $_POST['AdvSearchFinder']['Email']:"";
$modelAdvSearchFinder->attributes = $_POST['AdvSearchFinder'];
}
$id = Yii::app()->session['id'];
$name = Yii::app()->session['name'];
$age = Yii::app()->session['age'];
$class = Yii::app()->session['class'];
$section = Yii::app()->session['section'];
$Email = Yii::app()->session['Email'];
$criteria=new CDbCriteria(array('distinct'=>true,));
$criteria->compare('id',$id,true);
$criteria->compare('name',$name,true);
$criteria->compare('age',$age,true);
$criteria->compare('class',$class,true);
$criteria->compare('sectionPerson',$section,true);
$criteria->compare('Email',$Email,true);
if($id != "" || $name != "" || $age != "" || $class != "" || $section != "" || $Email != "" || $TelePhone1 != "" || $TelePhone2 != "" || $Fax != "" || $Address != "" || $State != "" || $Suburb != "" || $PostCode != "" || $Include_inactive != "F")
{
$modelSearch= new CActiveDataProvider("tblClass", array(
'criteria'=>$criteria,
));
}
else
{
$modelSearch = "";
$this->clearAdvSearchSessionVar();
}
$this->render('advance_search',array('modelSearch' => $modelSearch,'modelAdvSearchFinder'=>$modelAdvSearchFinder));
}
class AdvSearchFinder extends CFormModel
{
public $id;
public $name;
public $age;
public $class;
public $section;
public $Email;
public function rules()
{
return array(
array('id,name,age,class,section,Email', 'safe'),
);
}
public function attributeLabels()
{
return array(
'id'=>'ID',
'name'=>'Name',
'age'=>'AGE',
'class'=>'Class',
'section'=>'section',
'Email'=>'Email'
);
}
}
答案 0 :(得分:2)
unset(Yii::app()->session['var']);
答案 1 :(得分:2)
根据Orlymee的回答,您可以将其包装在控制器的支票中:
if(!Yii::app()->request->isAjaxRequest) {
unset(Yii::app()->session['var']);
}
答案 2 :(得分:2)
我有两个可以帮助您保留网格过滤器的扩展程序:
remember filters扩展为CActiveRecord / Model实现的默认可能性添加了一些功能。
它将检测搜索场景,它将从GridView中保存过滤器。当您需要在页面更改期间在导航之间记住它们时,这很方便。对于大量导航和重度过滤,此功能可以通过几行激活。
它的对是clear filters
答案 3 :(得分:0)
您可以使用jquery创建一个onclick事件,该事件将像其他用户所说的那样清除此会话:
unset(Yii::app()->session['var']);
答案 4 :(得分:0)
我不明白为什么你使用会话来存储请求变量,因为YII CActiveDataProvider已经有了设置请求参数的选项,可以用于排序和放大。分页如下:
$params=array('id'=>$_POST['AdvSearchFinder']['id'],'name'=>$_POST['AdvSearchFinder']['name'])
$dataProvider=new CActiveDataProvider($CmdbMaster,array(
'criteria'=>$criteria,
'pagination'=>array(
'params'=>$params,
),
'sort'=>array(
'params'=>$params,
),
));