Detailed description of searching by PAGE jQuery in YII framework, yiijquery

Source: Internet
Author: User

Detailed description of searching by PAGE jQuery in YII framework, yiijquery

Control Layer

Use frontend \ models \ StudUser; use yii \ data \ Pagination; use yii \ db \ Query;/*** Query **/public function actionSearch () {// connection value $ where = Yii: $ app-> request-> get (); // instantiate query $ query = new Query (); $ query-> from ('stud _ user'); // judge if (isset ($ where ['sex']) & $ where ['sex']! = '') {// Determine if ($ where ['sex'] = 'male ') {$ query-> andWhere (['stud _ sex '=> 0]);} if ($ where ['sex'] = 'female ') {$ query-> andWhere (['stud _ sex '=> 1]) ;}} else {$ where ['sex'] = '';} // age if (isset ($ where ['age']) & $ where ['age']! = '') {$ Query-> andWhere (['>', 'stud _ age', $ where ['age']);} else {$ where ['age'] = '';} // pagination $ Pagination = new pagination (['totalcount' => $ query-> count ()]); // number of items $ pagination-> setPageSize ('3'); // condition $ query-> offset ($ pagination-> offset)-> limit ($ pagination-> limit ); // execute $ userInfo = $ query-> all (); // print_r ($ userInfo); die; return $ this-> render ('search ', ['userinfo' => $ userInfo, 'page' => $ pagination, 'where' => $ where]);}

Model Layer

<? Phpnamespace frontend \ models; use Yii; use yii \ db \ ActiveRecord; class StudUser extends ActiveRecord {/*** declare table name **/public static function tableName () {return '{% stud_user}';}/*** verification rule **/public function rules () {return [['stud _ age ', 'integer'],] ;}}

View Layer

<? Phpuse yii \ widgets \ ActiveForm; use yii \ helpers \ Url; use yii \ helpers \ Html; use yii \ widgets \ LinkPager;?> <? Php $ form = ActiveForm: begin (['action' => Url: toRoute (['admin/search']), 'method' => 'get',]); echo 'gender ', "", Html: input ('text', 'sex ', $ where ['sex']); echo 'age', "", Html: input ('text', 'age', $ where ['age']); echo Html: submitButton ('Submit'); ActiveForm: end ();?> <Table class = "table"> <tr> <td> NO. </td> <td> name </td> <td> age </td> </tr> <? Php foreach ($ userInfo as $ val):?> <Tr> <td> <? = $ Val ['stud _ id']?> </Td> <? = $ Val ['stud _ name']?> </Td> <? = $ Val ['stud _ age']?> </Td> </tr> <? Php endforeach;?> </Table> <? Phpecho LinkPager: widget (['pagination' => $ page, 'nextpagelabel '=> 'Next page']);?>

The paging style is in

LinkPager. php

The above is a detailed description of the search paging jQuery method in the YII framework introduced by xiaobian. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.