Yii 1 Development Diary-----------search function and the implementation of checkbox

Source: Internet
Author: User

Use Yii 1 to achieve the background search function, such as:

1. In the Model:

1  Public functionSearch ()2     {3 4     $criteria=NewCdbcriteria;5         //Independent Advanced Search6         if(isset($_get[' Goods '])  ) {7             //article number8             if(isset($_get[' Goods '] [' GOODS_SN ']) &&$_get[' Goods '] [' GOODS_SN ']! = "")9             {Ten                 $criteria->compare (' Goods_sn ',$_get[' Goods '] [' GOODS_SN '],true ); One             } A             //Product Name -             if(isset($_get[' Goods '] [' Goods_name ']) &&$_get[' Goods '] [' goods_name ']! = "") -             { the                 $criteria->compare (' Goods_name ',$_get[' Goods '] [' Goods_name '],true); -             } -             //Product Categories -             if(isset($_get[' Goods '] [' cat_id ']) &&$_get[' Goods '] [' cat_id ']! = "") +             { -                 $criteria->compare (' cat_id ',$_get[' Goods '] [' cat_id '],true); +             } A             //whether shelves at             if(isset($_get[' Goods '] [' Is_on_sale ']) &&$_get[' Goods '] [' Is_on_sale ']! = "") -             { -                 $criteria->compare (' Is_on_sale ',$_get[' Goods '] [' Is_on_sale ']); -             } -             //whether the boutique -             if(isset($_get[' Goods '] [' Is_best ']) &&$_get[' Goods '] [' is_best ']! = "") in             { -                 $criteria->compare (' Is_best ',$_get[' Goods '] [' Is_best ']); to             } +             //whether new -             if(isset($_get[' Goods '] [' Is_new ']) &&$_get[' Goods '] [' is_new ']! = "") the             { *                 $criteria->compare (' Is_new ',$_get[' Goods '] [' Is_new ']); $             }Panax Notoginseng             //is hot -             if(isset($_get[' Goods '] [' Is_hot ']) &&$_get[' Goods '] [' is_hot ']! = "") the             { +                 $criteria->compare (' Is_hot ',$_get[' Goods '] [' Is_hot ']); A             } the  +         } -         return NewCactivedataprovider ($this,Array( $' Criteria ' =$criteria $         )); -}

2. In the controller:

$model=new b2cgoods (' Search ');

Indicates that search in the model is enabled for searching in models.

3. In the View:

<divclass= "Well" > <divclass= "Search-box" > <formclass= "Form-inline" method= "Get" action= "" >
        //Specify the page that form form submits, it is important<input type= ' hidden ' name= ' r ' value= ' b2cshop/b2cgoods/goodslist/id/<?php echo $id?> ' > <divclass= "Form-group" > <Input Name= "GOODS[GOODS_SN]"type= "Text"class= "Form-control"style= "width:140px;"placeholder= "article number"value=<?phpEcho $_get[' Goods '] [' GOODS_SN '];?> > </div>&nbsp; <divclass= "Form-group" > <Input Name= "Goods[goods_name]"type= "Text"class= "Form-control"style= "width:140px;"placeholder= "Product Name"value=<?phpEcho $_get[' Goods '] [' Goods_name '];?> > </div>&nbsp;&nbsp; <divclass= "Form-group" > <?phpEchoCHtml::d ropdownlist ("goods[cat_id]",$_get[' Goods '] [' cat_id '],b2ccategory:: ListData ($id) ,Array("Class" = "Form-control", ' empty ' = ' Please select Type ... ', ' encode ' =false, "style" = "width:140px")); ?> </div>&nbsp;&nbsp; <divclass= "checkbox" > <label style= "font-size:16px" >Shelves<input type= "checkbox"name= "Goods[is_on_sale]"style= "WIDTH:24PX;"value= "1"
                 //Implement CheckBox, Refresh page remains in original state<?phpEcho $_get[' Goods '] [' Is_on_sale ']? ' checked= "Checked" ': '?> > </label> </div>&nbsp;&nbsp; <divclass= "checkbox" > <label style= "font-size:16px" >Boutique<input type= "checkbox"name= "Goods[is_best]"style= "WIDTH:24PX;"value= "1" <?phpEcho $_get[' Goods '] [' Is_best ']? ' checked= "Checked" ': '?> > </label> </div>&nbsp;&nbsp; <divclass= "checkbox" > <label style= "font-size:16px" >New Products<input type= "checkbox"name= "Goods[is_new]"style= "WIDTH:24PX;"value= "1" <?phpEcho $_get[' Goods '] [' Is_new ']? ' checked= "Checked" ': '?> > </label> </div>&nbsp;&nbsp; <divclass= "checkbox" > <label style= "font-size:16px" >Hot<input type= "checkbox"name= "Goods[is_hot]"style= "WIDTH:24PX;"value= "1" <?phpEcho $_get[' Goods '] [' Is_hot ']? ' checked= "Checked" ': '?> > </label> </div> <b Utton type= "Submit"class= "Btn Btn-default" ><spanclass= "Glyphicon glyphicon-search" ></span>&nbsp; search &nbsp; cable </button> </form> &LT;/DIV&GT;&L T;/div>

One thing to note here is to implement a checkbox to keep the original state, <?php echo $_get[' goods ' [' is_hot ']? ' checked= "Checked" ': '?>, that is, using PHP to determine whether there is a value.

Yii 1 Development Diary-----------search function and the implementation of checkbox

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.