Home  >  Article  >  php教程  >  Yii framework search paging module writing method

Yii framework search paging module writing method

高洛峰
高洛峰Original
2016-12-23 17:10:001046browse

Controller layer

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   //把搜索的条件显示到前面
  ]);
     
  }
}

View layer





  
  商品的展示列表

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(); ?> $val): ?>
商品名称是:
$pages, 'nextPageLabel' => '下一页', 'prevPageLabel' => '上一页', ]); ?>

Model layer

The above is the Yii framework search paging module writing method introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message , the editor will reply to everyone in time. I would also like to thank you all for your support of the PHP Chinese website!

For more articles related to Yii framework search paging module writing methods, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn