zqcolor
遇到相同问题, 找到解决方法如下:
不管怎样,你需要一种能持久化数据的方式。你可以有以下几种选择:
- GET参数
- SESSION
- COOKIE
- hidden field
我的建议是尽量用GET参数,尤其是这种搜索查询页面。
在action中得到post数据后写入$_GET就行了
像这样$form=new SearchForm; if(isset($_POST['SearchForm'])) { $form->attributes=$_POST['SearchForm']; $_GET['keyword'] = $form->keyword; $_GET['cat_id'] = $form->cat_id; } elseif(isset($_GET['keyword'])) { if(isset($_GET['keyword'])) $form->keyword=$_GET['keyword']; if(isset($_GET['cat_id'])) $form->cat_id=$_GET['cat_id']; } else { 既没post也没get数据的话,设定默认查询条件 } if($form->validate()) { ....处理查询 }
我自己的代码, 范围搜索
if (!empty(Yii::$app->request->post())){ $result_from = Yii::$app->request->post('DemoCollectionSearch')['result_from']; $result_to = Yii::$app->request->post('DemoCollectionSearch')['result_to']; }else{ $result_from = Yii::$app->request->get('result_from'); $result_to = Yii::$app->request->get('result_to'); } $searchModel = new DemoCollectionSearch(); $searchModel->result_from = $result_from; $searchModel->result_to = $result_to; $_GET += array( 'result_from' => $dresult_from, 'result_to' => $result_to, ); // define
- zqcolor 2017-02-27 已签到连续签到1天,获得了5个金钱
遇到相同问题,看来解决方法一样,不知道有别的方法不? 一直以为yii2会提供一个方法类似getAllModels,看来目前还没有, 只有totalCount
- zqcolor 回答了问题 求个YII2下拉 二级联动 实例
Yii2 中国省市区三级联动, 有详细介绍截图, $model 对应自己建立的保存地址信息的表
http://www.yiichina.com/tutorial/1053 - zqcolor 评论了教程 activeform三级联动
我用的下面这个,介绍较详细
Yii2 中国省市区三级联动, 有详细介绍截图, $model 对应自己建立的保存地址信息的表
http://www.yiichina.com/tutorial/1053 可以用现成框架, yii2-starter-kit + OAuth 2.0 extension
ssl 用let's encrypt- zqcolor 2016-10-18 已签到连续签到1天,获得了5个金钱
- zqcolor 2016-10-12 已签到连续签到1天,获得了5个金钱