Yii1 development diary ----------- search function and Checkbox implementation use yii1 to implement the background search function, the effect is as follows: 1. model: 1 publicfunctionsearch () 2 {34 $ criterianewCDbCriteria; 5 independent Advanced search 6if (isse Yii 1 development diary ----------- search function and Checkbox implementation
Use yii 1 to implement the background search function. The results are as follows:
1. in the model:
1 public function search () 2 {3 4 $ criteria = new CDbCriteria; 5 // independent Advanced search 6 if (isset ($ _ GET ['Goods ']) {7 // product lifecycle 8 if (isset ($ _ GET ['Goods '] ['goods _ sn']) & $ _ GET ['Goods '] ['goods _ sn']! = "") 9 {10 $ criteria-> compare ('goods _ sn ', $ _ GET ['Goods'] ['goods _ sn '], true ); 11} 12 // product name 13 if (isset ($ _ GET ['Goods '] ['goods _ name']) & $ _ GET ['Goods '] ['goods _ name']! = "") 14 {15 $ criteria-> compare ('goods _ name', $ _ GET ['Goods '] ['goods _ name'], true ); 16} 17 // product category 18 if (isset ($ _ GET ['Goods '] ['cat _ id']) & $ _ GET ['Goods '] ['cat _ id']! = "") 19 {20 $ criteria-> compare ('cat _ id', $ _ GET ['Goods '] ['cat _ id'], true ); 21} 22 // whether to mount 23 if (isset ($ _ GET ['Goods '] ['is _ on_sale']) & $ _ GET ['Goods '] ['is _ on_sale']! = "") 24 {25 $ criteria-> compare ('is _ on_sale ', $ _ GET ['Goods'] ['is _ on_sale ']); 26} 27 // whether the boutique 28 if (isset ($ _ GET ['Goods '] ['is _ best']) & $ _ GET ['Goods '] ['is _ best']! = "") 29 {30 $ criteria-> compare ('is _ best', $ _ GET ['Goods '] ['is _ best']); 31} 32 // new Product 33 if (isset ($ _ GET ['Goods '] ['is _ new']) & $ _ GET ['Goods '] ['is _ new']! = "") 34 {35 $ criteria-> compare ('is _ new', $ _ GET ['Goods '] ['is _ new']); 36} 37 // whether to sell hot 38 if (isset ($ _ GET ['Goods '] ['is _ hot']) & $ _ GET ['Goods '] ['is _ hot']! = "") 39 {40 $ criteria-> compare ('is _ hot ', $ _ GET ['Goods'] ['is _ hot ']); 41} 42 43} 44 return new CActiveDataProvider ($ this, array (45 'criteria '=> $ criteria46); 47}
2. in the controller:
$model=new B2cGoods('search');
Enable search in the model as search.
3. view:
Note that checkbox is implemented to keep the original state, Php is used to determine whether a value exists.