yii框架搜索分页modle写法
2016-12-19 11:02
731 查看
控制器层
<?PHP namespace frontend\controllers; header('content-type:text/html;charset=utf-8'); use Yii; use yii\base\InvalidParamException; use yii\web\BadRequestHttpException; use yii\web\Controller; use yii\filters\VerbFilter; use yii\filters\AccessControl; use common\models\LoginForm; use frontend\models\PasswordResetRequestForm; use frontend\models\ResetPasswordForm; use frontend\models\SignupForm; use frontend\models\ContactForm; use frontend\models\Goods; //加载jidian 表的model use yii\data\Pagination; //yii框架中使用分页 use frontend\web\myclass\QRcode;//加载生成二维码类 /** * Site controller */ class GoodsController extends Controller { public $enableCsrfValidation = false; //商品展示列表 public function actionGoodslist() { //接收过来搜索的条件 $w=yii::$app->request->get('goods_name'); //分页 $test=new Goods(); //实例化model模型 $arr=$test->find()->where(['like','goods_name',"$w"]); //加上搜索的条件where $pages = new Pagination([ 'totalCount' => $arr->count(), 'pageSize' => 4 //每页显示条数 ]); $models = $arr->offset($pages->offset) ->limit($pages->limit) ->all(); return $this->render('goodslist', [ //前台的页面 'data' => $models, 'pages' => $pages, 'where' =>$w //把搜索的条件显示到前面 ]); } }
视图层
<?php use yii\widgets\ActiveForm; use yii\helpers\Url; use yii\helpers\Html; use yii\widgets\LinkPager; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>商品的展示列表</title> </head> <body> <?php $form=ActiveForm::begin([ 'action'=>Url::toRoute(['goods/goodslist']), 'method'=>'get', ]); echo '搜索'," ",Html::input('text','goods_name',$where); // echo '年龄'," ",Html::input('text','age',$where['age']); echo Html::submitButton('搜索'); ActiveForm::end(); ?> <table> <?php foreach ($data as $key => $val): ?> <tr> <td>商品名称是:<?= $val['goods_name']?></td> </tr> <?php endforeach ?> </table> </body> </html> <?php // use yii\widgets\LinkPager; echo LinkPager::widget([ 'pagination' => $pages, 'nextPageLabel' => '下一页', 'prevPageLabel' => '上一页', ]); ?>
model层
<?php namespace frontend\models; use Yii; class Goods extends \yii\db\ActiveRecord { }
以上所述是小编给大家介绍的yii框架搜索分页modle写法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章:
相关文章推荐
- Yii框架搜索分页
- YII框架中搜索分页jQuery写法详解
- YII框架中自带的表单,搜索 4000 ,分页代码的实现
- PHP Yii框架分页搜索, 个人自创源码,不喜勿碰。
- YII框架中搜索分页jQuery写法详解
- Yii框架结合sphinx,Ajax实现搜索分页功能示例
- yii框架中,搜索的表单和后台执行,以及分页
- yii框架里ajax分页和搜索 单删 批删
- YII框架中自带的表单,搜索,分页代码的实现
- Yii框架结合sphinx,Ajax实现搜索分页功能示例
- yii框架搜索后分页查询方法
- YII框架中自带的表单,搜索,分页代码的实现
- yii增删改查搜索分页
- yii2框架中使用下拉菜单的自动搜索yii-widget-select2
- ThinkPHP 3.1 框架--分页搜索的应用
- YII 框架 第六天(1) YII和分页
- yii框架搜索分页modle写法
- Zend Framework框架实现类似Google搜索分页效果
- SSM框架——实现分页和搜索分页
- yii框架分页的实现