yii框架所搜分页
来源:互联网 发布:数据挖掘软件 编辑:程序博客网 时间:2024/06/07 05:36
注意:我form表单提交的地址明明是/blog-advanced/backend/web/index.php?r=sys/index
的路径,提交后直接给我变成/blog-advanced/backend/web/index.php
了,但是用post的方式提交路径和action的一样,难道是 get 方式提交不支持这样的 url 路径吗? 知情人士请回答在你的表单里面加上一个隐藏域,再次提交时就会在URL中拼凑出r='sys/index'这一段了<input type="hidden" name="r" value="sys/index">
views:视图层<?phpuse yii\helpers\Html;use yii\bootstrap\ActiveForm;use yii\helpers\Url;use yii\base;use\yii\widgets\LinkPager;?><!doctype html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title></head><center><body><?php$form=ActiveForm::begin([ 'action'=>Url::toRoute(['showc']), 'method'=>'get',]);echo '姓名:'.Html::input('text','username',$search);//可以写第三个值,相当于value保留值,但是添加成功不显示&username,能力强大的人可以解决一波echo Html::submitButton();ActiveForm::end();echo "<br/>";?><!-- <form action="index.php?r=ceshi/showc" method="get">--><!-- <input type="hidden" name="_csrf-frontend" value=""/>--><!-- 请输入姓名<input type="text" name="search"><input type="submit" value="查询"/>--><!-- </form>--> <table border="1"> <tr> <td>id</td> <td>用户名</td> <td>性别</td> <td>爱好</td> <td>学历</td> <td>操作</td> </tr> <?php foreach($date as $val){?> <tr> <td><?= $val['id']?></td> <td><?= $val['username']?></td> <td><?= $val['sex']?></td> <td><?= $val['hobby']?></td> <td><?= $val['xueli']?></td> <td><a href="?r=ceshi/desca&id=<?= $val['id']?>">详情</a></td> </tr> <?php }?> </table> <?= LinkPager::widget([ 'pagination' => $pages, 'nextPageLabel' => '下一页', 'prevPageLabel' => '上一页', 'firstPageLabel' => '首页', 'lastPageLabel' => '尾页', ]); ?></body></center></html>controller:控制层public function actionShowc(){ $db=\Yii::$app->db;// $count=$db->createCommand("select COUNT(*) from ceshi")->queryScalar();// $pages= new Pagination(['totalCount'=>$count,'pageSize'=>3]);// $date=$db->createCommand("select * from ceshi")->queryAll(); $user=empty($_GET['username'])?'':$_GET['username'];// print_r($user);die; if(!empty($user)){ $query = Ceshi::find()->where("username like '%$user%'"); }else{ $query = Ceshi::find(); } $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(),'pageSize'=>3]); $date = $query->offset($pages->offset) ->limit($pages->limit) ->all(); $xuel=$db->createCommand("select * from ceshixueli")->queryAll(); //把另一个表里的值循环添加到另一个表中// print_r($date);die; foreach($date as &$val){ foreach($xuel as &$va){ if($val['xueli']==$va['id']){ $val['xueli']=$va['xueli']; } } }// print_r($date);die; return $this->render('showc',['date'=>$date,'search'=>$user,'pages'=>$pages]); }model:模型<?phpnamespace frontend\models;use Yii;use yii\base\Model;use yii\web\UploadedFile;use yii\captcha\Captcha;/** * Login form */class Ceshi extends \yii\db\ActiveRecord{ //模式必须把verifycode 加属性加上否则报错// public $username;// public $userpwd;// public $userfile;// public $addtime;// public $verifyCode;// public $sex;// public $hobby;// public $xueli; /** * @inheritdoc */ public function rules() { return [ // username and password are both required [['username', 'userpwd'], 'required'], [['userfile'], 'file', 'extensions' => 'png, jpg', 'maxFiles' => 4], ['verifyCode', 'required'], ['verifyCode', 'captcha','captchaAction'=>'ceshi/captcha'], [['sex','hobby'], 'string'], [['sex','hobby','xueli'], 'required'], // rememberMe must be a boolean value // password is validated by validatePassword()// ['password', 'validatePassword'], ]; } public function attributeLabels() { return [ 'username' => '昵称', 'userpwd' => '密码', 'verifyCode' => '验证码', 'userfile' => '头像', 'addtime' => '有效期', 'sex' => '性别', 'hobby' => '爱好', 'xueli' => '学历', ]; }
阅读全文
0 0
- yii框架所搜分页
- 【Yii框架】YII分页组件
- yii框架分页
- yii框架中的分页
- Yii框架搜索分页
- yii框架数据分页
- yii 框架分页
- Yii框架的分页
- yii框架分页的实现
- yii 框架中的上传 分页
- yii框架中的两表联查+分页
- yii框架查询分页展示
- yii框架引入coreseek 分页
- Yii框架—搜索分页
- yii框架搜索后分页
- Yii框架自带分页
- yii框架ajax分页的使用
- yii框架中搜索分页Query写法
- Python sqlite3 模块 API
- 序言
- android 6.0以后动态申请多个危险权限笔记
- (8)nodejs学习--express整合模板引擎
- Python Study (01) 之 特殊方法
- yii框架所搜分页
- Zookeeper Golang客户端:go-zookeeper的基本使用
- yum安装报错“Error: xz compression not available”
- 超级记忆法(3)——第一小时
- trafodion导入ORC文件压缩方式是snappy
- 2048小游戏c语言实现
- 作为初学者学C语言的小小总结
- 机器学习-决策树和随机森林
- 输出时间和成绩平均分到指定位置