Yii1 Development Diary, yii development diary _ PHP Tutorial

Source: Internet
Author: User
Yii1 development diary and yii development diary. Yii1 Development Diary, yii development diary use yii1 to implement the background search function, the effect is as follows: 1. in the model: 1 publicfunctionsearch () 2 {34 $ criterianewCDbCriteria; 5 independent Yii 1 development diary, yii development diary

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.

Http://www.bkjia.com/PHPjc/1071503.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1071503.htmlTechArticleYii 1 development diary, yii development diary with yii 1 realize the background search function, the effect is as follows: 1. in the model: 1 public function search () 2 {3 4 $ criteria = new CDbCriteria; 5 // independent...

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.