Yii 1开发日记,yii开发日记_PHP教程

原创
2016-07-12 09:04:47 706浏览

Yii 1开发日记,yii开发日记


用yii 1实现后台的搜索功能,效果如下图:

1.模型中:

 1 public function search()
 2     {
 3 
 4     $criteria = new CDbCriteria;
 5         //独立高级搜索
 6         if(isset( $_GET['goods'])  ) {
 7             //商品货号
 8             if (isset($_GET['goods']['goods_sn']) && $_GET['goods']['goods_sn'] != "")
 9             {
10                 $criteria->compare('goods_sn',$_GET['goods']['goods_sn'], true );
11             }
12             //商品名称
13             if (isset($_GET['goods']['goods_name']) && $_GET['goods']['goods_name'] != "")
14             {
15                 $criteria->compare('goods_name',$_GET['goods']['goods_name'], true);
16             }
17             //商品分类
18             if (isset($_GET['goods']['cat_id']) && $_GET['goods']['cat_id'] != "")
19             {
20                 $criteria->compare('cat_id',$_GET['goods']['cat_id'], true);
21             }
22             //是否上架
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             //是否精品
28             if (isset($_GET['goods']['is_best']) && $_GET['goods']['is_best'] != "")
29             {
30                 $criteria->compare('is_best',$_GET['goods']['is_best']);
31             }
32             //是否新品
33             if (isset($_GET['goods']['is_new']) && $_GET['goods']['is_new'] != "")
34             {
35                 $criteria->compare('is_new',$_GET['goods']['is_new']);
36             }
37             //是否热销
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'=>$criteria
46         ));
47 }

2.控制器中:

$model=new B2cGoods('search');

表示在model中启用模型中的search作为搜索。

3.视图中:

class="well">
class="search-box">
class="form-inline" method="get" action="">
       //指定form表单提交的页面,很重要
class="form-group"> <input name="goods[goods_sn]" type="text" class="form-control" style="width:140px;" placeholder = "商品货号" value=echo $_GET['goods']['goods_sn'] ; ?> >
&nbsp;
class="form-group"> <input name="goods[goods_name]" type="text" class="form-control" style="width:140px;" placeholder = "商品名称"   value=echo $_GET['goods']['goods_name'] ; ?> >
&nbsp;
class="form-group"> echo CHtml::dropDownList( "goods[cat_id]" , $_GET['goods']['cat_id'] , B2cCategory::listData( $id ) , array( "class"=>"form-control" , 'empty'=>'请选择类型...', 'encode' => false, "style"=>"width:140px") ); ?>
&nbsp;
class="checkbox">
&nbsp;
class="checkbox">
&nbsp;
class="checkbox">
&nbsp;
class="checkbox">

这里需要注意的一点是实现checkbox,保持原状态,echo $_GET['goods']['is_hot']?'checked="checked"':'' ?>,即用php判断是否有值。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1071503.htmlTechArticleYii 1开发日记,yii开发日记 用yii 1实现后台的搜索功能,效果如下图: 1.模型中: 1 public function search() 2 { 3 4 $criteria = new CDbCriteria; 5 // 独立...

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
上一条:在php中需要用到的mysql数据库的简单操作,phpmysql_PHP教程 下一条:PHP经典题:百钱百鸡问题(穷举算法)_PHP教程

相关文章

查看更多