我使用的是$ _GET而不是$ _POST,但我不喜欢在网址上显示结果或型号名称
在视图中我让表单类型为GET而不是POST
$form = $this->beginWidget('CActiveForm', array(
'action' => Yii::app()->createUrl('/OperationReport'),
'method'=>'GET',
));
在控制器
public function actionReportform() {
$operation = new Operation ;
$this->render('reportform', array(
'model' => $operation,
));
}
public function actionOperationReport() {
$this->layout = '//layouts/report';
$status = CHtml::encode($_GET['Operation']['status']);
$date1 = CHtml::encode($_GET['Operation']['reception_date']);
$date2 = CHtml::encode($_GET['Operation']['reception_date_2']);
$criteria = new CDbCriteria;
$criteria->condition = "user_id =:userid";
$criteria->params =array(':userid'=> Yii::app()->user->id) ;
$criteria->order = 'reception_date DESC ';
!empty($date1) ? $criteria->addInCondition('reception_date >', array($date1)) : "";
!empty($date2) ? $criteria->addInCondition('reception_date <', array($date2)) : "";
!empty($status) ? $criteria->addInCondition('status ', array($status)) : "";
$result = Operation::model()->findAll($criteria);
if ($result == null) {
throw new CHttpException(404, 'There is no result for your selection .');
} else {
$this->render('OperationReport', array(
'operations'=>$result ,
'reception_date'=>$date1,
'reception_date_2'=>$date2,
'status'=>$status,
));
}
}
我前一段时间做过这个,但是我忘了它是用GET还是POST
答案 0 :(得分:1)
最好的解决方案是POST方法。 GET方法不适用于具有多个字段的表单。
答案 1 :(得分:0)
您可以查看路由和urlManager,但是如果您真的需要这样做并且您没有处理灵活的参数,那么以这种方式管理网址会变得非常潮湿。请记住这对全球网站的影响。 要重写特定网址,您可以将此行添加到config.php中的urlManager。
'urlManager' => array(
'urlFormat' => 'path',
'appendParams' => false,
'showScriptName' => false, // to remove index.php from urls
'rules' => array(
'' => 'site/index', //optional: makes your homepage http://domain.com/
'<controller:(operation)>/<action:(operationReport)>/reception_date/<Operation[reception_date]>/reception_date_2/<Operation[reception_date_2]>/status/<Operation[status]>' => 'operation/operationReport'
),
)
我还没有对规则进行测试,但它应该按照你的需要进行测试