基于角色的存取控制 (RBAC)
基于角色的存取控制 (RBAC) 提供了一个简单而强大的集中式存取控制机制。 详细的关于 RBAC 和诸多传统的存取控制方案对比的详情,请参阅 Wikipedia。
Yii 实现了通用的分层的 RBAC,遵循的模型是 NIST RBAC model. 它通过 authManager application component 提供 RBAC 功能。
使用 RBAC 涉及到两部分工作。第一部分是建立授权数据, 而第二部分是使用这些授权数据在需要的地方执行检查。
为方便后面的讲述,这里先介绍一些 RBAC 的基本概念。
基本概念
角色是 权限 的集合 (例如:建贴、改贴)。一个角色 可以指派给一个或者多个用户。要检查某用户是否有一个特定的权限, 系统会检查该包含该权限的角色是否指派给了该用户。
可以用一个规则 rule 与一个角色或者权限关联。一个规则用一段代码代表, 规则的执行是在检查一个用户是否满足这个角色或者权限时进行的。例如,"改帖" 的权限 可以使用一个检查该用户是否是帖子的创建者的规则。权限检查中,如果该用户 不是帖子创建者,那么他(她)将被认为不具有 "改帖"的权限。
角色和权限都可以按层次组织。特定情况下,一个角色可能由其他角色或权限构成, 而权限又由其他的权限构成。Yii 实现了所谓的 局部顺序 的层次结构,包含更多的特定的 树 的层次。 一个角色可以包含一个权限,反之则不行。(译者注:可理解为角色在上方,权限在下方,从上到下如果碰到权限那么再往下不能出现角色)
配置 RBAC
在开始定义授权数据和执行存取检查之前,需要先配置应用组件 authManager 。 Yii 提供了两套授权管理器: yii\rbac\PhpManager 和 yii\rbac\DbManager。前者使用 PHP 脚本存放授权数据, 而后者使用数据库存放授权数据。 如果你的应用不要求大量的动态角色和权限管理, 你可以考虑使用前者。
使用 PhpManager
以下代码展示使用 yii\rbac\PhpManager 时如何在应用配置文件中配置 authManager
:
return [ // ... 'components' => [ 'authManager' => [ 'class' => 'yii\rbac\PhpManager', ], // ... ], ];
现在可以通过 \Yii::$app->authManager
访问 authManager
。
yii\rbac\PhpManager 默认将 RBAC 数据保存在 @app/rbac
目录下的文件中。 如果权限层次数据在运行时会被修改,需确保WEB服务器进程对该目录和其中的文件有写权限。
使用 DbManager
以下代码展示使用 yii\rbac\DbManager 时如何在应用配置文件中配置 authManager
:
1 return [ 2 // ... 3 'components' => [ 4 'authManager' => [ 5 'class' => 'yii\rbac\DbManager', 6 // uncomment if you want to cache RBAC items hierarchy 7 // 'cache' => 'cache', 8 ], 9 // ... 10 ], 11 ];
DbManager
使用4个数据库表存放它的数据:
- itemTable: 该表存放授权条目(译者注:即角色和权限)。默认表名为 "auth_item" 。
- itemChildTable: 该表存放授权条目的层次关系。默认表名为 "auth_item_child"。
- assignmentTable: 该表存放授权条目对用户的指派情况。默认表名为 "auth_assignment"。
- ruleTable: 该表存放规则。默认表名为 "auth_rule"。
继续之前,你需要在数据库中创建这些表。你可以使用存放在 @yii/rbac/migrations
目录中的数据库迁移文件来做这件事(译者注:根据本人经验,最好是将授权数据初始化命令也写到这个 RBAC 数据库迁移文件中):
1 yii migrate --migrationPath=@yii/rbac/migrations
1 <?php 2 namespace backend\controllers; 3 4 use Yii; 5 use yii\web\Controller; 6 class GoodsController extends Controller{ 7 public $enableCsrfValidation=false; 8 public $layout=false; 9 //渲染頁面 10 public function actionIndex(){ 11 $this->layout=false; 12 $id = yii::$app->user->getId(); 13 $auth = Yii::$app->authManager; 14 $menu = $auth->getPermissionsByUser($id); 15 // echo "<pre>"; 16 // var_dump($menu); 17 return $this->render('index',['menu'=>$menu]); 18 } 19 //商品添加 20 public function actionGoods_add() 21 { 22 if (Yii::$app->request->isPost) { 23 $data = Yii::$app->request->post(); 24 $data['addtime'] = time(); 25 $res = Yii::$app->db->createCommand()->insert('goods', $data)->execute(); 26 if ($res) { 27 return $this->redirect(['goods/goods_list']); 28 } else { 29 $this->redirect(['goods/goods_add']); 30 } 31 } 32 return $this->render('goods_add'); 33 } 34 //商品展示 35 public function actionGoods_list(){ 36 $data = Yii::$app->db->createCommand('select * from goods')->queryAll(); 37 return $this->render('goods_list',['data'=>$data]); 38 } 39 //刪除 40 public function actionGoods_del(){ 41 $id = $_GET['id']; 42 if(Yii::$app->db->createCommand()->delete('goods', ['id'=>$id])->execute()){ 43 return $this->redirect(['goods/goods_list']); 44 } 45 } 46 public function actionGoods_update(){ 47 $id =yii::$app->request->get('id'); 48 $name =yii::$app->request->get('name'); 49 $price =yii::$app->request->get('price'); 50 $stock =yii::$app->request->get('stock'); 51 $data = Yii::$app->db->createCommand('SELECT * FROM goods')->queryOne(); 52 $data = Yii::$app->db->createCommand()->update('goods', ['name' => $name],['price'=>$price],['syock'=>$stock],'id = $id')->execute(); 53 return $this->render('goods_update',['data'=>$data]); 54 echo "<pre>"; 55 var_dump($data); 56 } 57 }
1 <?php 2 use yii\helpers\Url; 3 4 ?> 5 <!DOCTYPE html> 6 <html> 7 8 <head> 9 <meta charset="utf-8"> 10 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 11 <meta name="renderer" content="webkit"> 12 13 <title> hAdmin- 主页</title> 14 15 <meta name="keywords" content=""> 16 <meta name="description" content=""> 17 18 <!--[if lt IE 9]> 19 <meta http-equiv="refresh" content="0;ie.html" /> 20 <![endif]--> 21 22 <link rel="shortcut icon" href="favicon.ico"> <link href="css/static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet"> 23 <link href="css/static/css/font-awesome.min.css?v=4.4.0" rel="stylesheet"> 24 <link href="css/static/css/animate.css" rel="stylesheet"> 25 <link href="css/static/css/style.css?v=4.1.0" rel="stylesheet"> 26 </head> 27 28 <body class="fixed-sidebar full-height-layout gray-bg" style="overflow:hidden"> 29 <div id="wrapper"> 30 <!--左侧导航开始--> 31 <nav class="navbar-default navbar-static-side" role="navigation"> 32 <div class="nav-close"><i class="fa fa-times-circle"></i> 33 </div> 34 <div class="sidebar-collapse"> 35 <ul class="nav" id="side-menu"> 36 <li class="nav-header"> 37 <div class="dropdown profile-element"> 38 <a data-toggle="dropdown" class="dropdown-toggle" href="#"> 39 <span class="clear"> 40 <span class="block m-t-xs" style="font-size:20px;"> 41 <i class="fa fa-area-chart"></i> 42 <strong class="font-bold">hAdmin</strong> 43 </span> 44 </span> 45 </a> 46 </div> 47 <div class="logo-element">hAdmin 48 </div> 49 </li> 50 <li class="hidden-folded padder m-t m-b-sm text-muted text-xs"> 51 <span class="ng-scope">商城</span> 52 </li> 53 <li> 54 <a class="J_menuItem" href="index_v1.html"> 55 <i class="fa fa-home"></i> 56 <span class="nav-label">主页</span> 57 </a> 58 </li> 59 <li> 60 <a href="#"> 61 <i class="fa fa fa-bar-chart-o"></i> 62 <span class="nav-label">商品表</span> 63 <span class="fa arrow"></span> 64 </a> 65 <ul class="nav nav-second-level"> 66 <li> 67 <a class="J_menuItem" href="<?=Url::to(['goods/goods_add'])?>">添加商品</a> 68 </li> 69 <li> 70 <a class="J_menuItem" href="<?=Url::to(['goods/goods_list'])?>">商品展示</a> 71 </li> 72 </ul> 73 </li> 74 <li class="line dk"></li> 75 <li> 76 <a href="#"> 77 <i class="fa fa fa-bar-chart-o"></i> 78 <span class="nav-label">商品分類表</span> 79 <span class="fa arrow"></span> 80 </a> 81 <ul class="nav nav-second-level"> 82 <li> 83 <a class="J_menuItem" href="<?=Url::to(['types/types_add'])?>">添加商品分類</a> 84 </li> 85 <li> 86 <a class="J_menuItem" href="<?=Url::to(['types/types_list'])?>">商品分類展示</a> 87 </li> 88 </ul> 89 </li> 90 <li class="line dk"></li> 91 <li> 92 <a href="#"> 93 <i class="fa fa fa-bar-chart-o"></i> 94 <span class="nav-label">自定義菜單</span> 95 <span class="fa arrow"></span> 96 </a> 97 <ul class="nav nav-second-level"> 98 <li> 99 <a class="J_menuItem" href="<?=Url::to(['day/createmenu'])?>">創建菜單</a> 100 </li> 101 <li> 102 <a class="J_menuItem" href="<?=Url::to(['day/qurestmenu'])?>">查詢菜單</a> 103 </li> 104 <li> 105 <a class="J_menuItem" href="<?=Url::to(['day/deletemenu'])?>">刪除菜單</a> 106 </li> 107 </ul> 108 </li> 109 <li class="line dk"></li> 110 <li> 111 <a href="#"> 112 <i class="fa fa fa-bar-chart-o"></i> 113 <span class="nav-label">菜單</span> 114 <span class="fa arrow"></span> 115 </a> 116 <ul class="nav nav-second-level"> 117 118 <li> 119 <?php foreach ($menu as $key=>$val){?> 120 <a class="J_menuItem" href="<?=Url::to([$val->name])?>"><?=$val->description?></a> 121 <?php }?> 122 </li> 123 </ul> 124 </li> 125 </ul> 126 </div> 127 </nav> 128 <!--左侧导航结束--> 129 <!--右侧部分开始--> 130 <div id="page-wrapper" class="gray-bg dashbard-1"> 131 <div class="row border-bottom"> 132 <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0"> 133 <div class="navbar-header"><a class="navbar-minimalize minimalize-styl-2 btn btn-info " href="#"><i class="fa fa-bars"></i> </a> 134 <form role="search" class="navbar-form-custom" method="post" action="search_results.html"> 135 <div class="form-group"> 136 <input type="text" placeholder="请输入您需要查找的内容 …" class="form-control" name="top-search" id="top-search"> 137 </div> 138 </form> 139 </div> 140 <ul class="nav navbar-top-links navbar-right"> 141 <li class="dropdown"> 142 <a class="dropdown-toggle count-info" data-toggle="dropdown" href="#"> 143 <i class="fa fa-envelope"></i> <span class="label label-warning">16</span> 144 </a> 145 <ul class="dropdown-menu dropdown-messages"> 146 <li class="m-t-xs"> 147 <div class="dropdown-messages-box"> 148 <a href="profile.html" class="pull-left"> 149 <img alt="image" class="img-circle" src="img/a7.jpg"> 150 </a> 151 <div class="media-body"> 152 <small class="pull-right">46小时前</small> 153 <strong>小四</strong> 是不是只有我死了,你们才不骂爵迹 154 <br> 155 <small class="text-muted">3天前 2014.11.8</small> 156 </div> 157 </div> 158 </li> 159 <li class="divider"></li> 160 <li> 161 <div class="dropdown-messages-box"> 162 <a href="profile.html" class="pull-left"> 163 <img alt="image" class="img-circle" src="img/a4.jpg"> 164 </a> 165 <div class="media-body "> 166 <small class="pull-right text-navy">25小时前</small> 167 <strong>二愣子</strong> 呵呵 168 <br> 169 <small class="text-muted">昨天</small> 170 </div> 171 </div> 172 </li> 173 <li class="divider"></li> 174 <li> 175 <div class="text-center link-block"> 176 <a class="J_menuItem" href="mailbox.html"> 177 <i class="fa fa-envelope"></i> <strong> 查看所有消息</strong> 178 </a> 179 </div> 180 </li> 181 </ul> 182 </li> 183 <li class="dropdown"> 184 <a class="dropdown-toggle count-info" data-toggle="dropdown" href="#"> 185 <i class="fa fa-bell"></i> <span class="label label-primary">8</span> 186 </a> 187 <ul class="dropdown-menu dropdown-alerts"> 188 <li> 189 <a href="mailbox.html"> 190 <div> 191 <i class="fa fa-envelope fa-fw"></i> 您有16条未读消息 192 <span class="pull-right text-muted small">4分钟前</span> 193 </div> 194 </a> 195 </li> 196 <li class="divider"></li> 197 <li> 198 <a href="profile.html"> 199 <div> 200 <i class="fa fa-qq fa-fw"></i> 3条新回复 201 <span class="pull-right text-muted small">12分钟钱</span> 202 </div> 203 </a> 204 </li> 205 <li class="divider"></li> 206 <li> 207 <div class="text-center link-block"> 208 <a class="J_menuItem" href="notifications.html"> 209 <strong>查看所有 </strong> 210 <i class="fa fa-angle-right"></i> 211 </a> 212 </div> 213 </li> 214 </ul> 215 </li> 216 </ul> 217 </nav> 218 </div> 219 <div class="row J_mainContent" id="content-main"> 220 <iframe id="J_iframe" width="100%" height="100%" src="index_v1.html?v=4.0" frameborder="0" data-id="index_v1.html" seamless></iframe> 221 </div> 222 </div> 223 <!--右侧部分结束--> 224 </div> 225 226 <!-- 全局js --> 227 <script src="css/static/js/jquery.min.js?v=2.1.4"></script> 228 <script src="css/static/js/bootstrap.min.js?v=3.3.6"></script> 229 <script src="css/static/js/plugins/metisMenu/jquery.metisMenu.js"></script> 230 <script src="css/static/js/plugins/slimscroll/jquery.slimscroll.min.js"></script> 231 <script src="css/static/js/plugins/layer/layer.min.js"></script> 232 233 <!-- 自定义js --> 234 <script src="css/static/js/hAdmin.js?v=4.1.0"></script> 235 <script type="text/javascript" src="css/static/js/index.js"></script> 236 237 <!-- 第三方插件 --> 238 <script src="css/static/js/plugins/pace/pace.min.js"></script> 239 <div style="text-align:center;"> 240 <p>来源:<a href="http://www.mycodes.net/" target="_blank">源码之家</a></p> 241 </div> 242 </body> 243 244 </html>
1 <?php 2 use yii\helpers\Url; 3 ?> 4 <!DOCTYPE html> 5 <html> 6 7 <head> 8 9 <meta charset="utf-8"> 10 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 11 12 13 <title> - 基本表单</title> 14 <meta name="keywords" content=""> 15 <meta name="description" content=""> 16 17 <link rel="shortcut icon" href="favicon.ico"> <link href="css/static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet"> 18 <link href="css/static/css/font-awesome.css?v=4.4.0" rel="stylesheet"> 19 <link href="css/static/css/plugins/iCheck/custom.css" rel="stylesheet"> 20 <link href="css/static/css/animate.css" rel="stylesheet"> 21 <link href="css/static/css/style.css?v=4.1.0" rel="stylesheet"> 22 </head> 23 <body class="gray-bg"> 24 <div class="wrapper wrapper-content animated fadeInRight"> 25 <div class="row"> 26 <div class="col-sm-12"> 27 <div class="ibox float-e-margins"> 28 </div> 29 <div class="ibox-content"> 30 <form method="post" class="form-horizontal"> 31 <div class="form-group"> 32 <label class="col-sm-2 control-label">商品分類</label> 33 <div class="col-sm-10"> 34 <select class="form-control m-b" name="type_id"> 35 <option value="1">家電</option> 36 <option value="2">海鮮</option> 37 <option value="3">生鮮</option> 38 <option value="4">酒水</option> 39 </select> 40 </div> 41 </div> 42 <div class="hr-line-dashed"></div> 43 <div class="form-group"> 44 <label class="col-sm-2 control-label">商品名稱</label> 45 <div class="col-sm-10"> 46 <input type="text" class="form-control" name="name"> 47 </div> 48 </div> 49 <div class="hr-line-dashed"></div> 50 <div class="form-group"> 51 <label class="col-sm-2 control-label">商品價格</label> 52 <div class="col-sm-10"> 53 <input type="text" class="form-control" name="price"> 54 </div> 55 </div> 56 <div class="hr-line-dashed"></div> 57 <div class="form-group"> 58 <label class="col-sm-2 control-label">商品庫存</label> 59 <div class="col-sm-10"> 60 <input type="text" class="form-control" name="stock"> 61 </div> 62 </div> 63 <div class="hr-line-dashed"></div> 64 <div class="form-group"> 65 <label class="col-sm-2 control-label">商品分類</label> 66 <div class="col-sm-10"> 67 <div class="radio i-checks"> 68 <label> 69 <input type="radio" value="0" name="status"> <i></i>上架</label> 70 </div> 71 <div class="radio i-checks"> 72 <label> 73 <input type="radio" value="1" name="status"> <i></i>下架</label> 74 </div> 75 </div> 76 </div> 77 <div class="hr-line-dashed"></div> 78 <div class="form-group"> 79 <div class="col-sm-4 col-sm-offset-2"> 80 <button class="btn btn-primary" type="submit">添加</button> 81 <button class="btn btn-white" type="reset">重置</button> 82 </div> 83 </div> 84 </form> 85 </div> 86 </div> 87 </div> 88 </div> 89 <!-- 全局js --> 90 <script src="css/static/js/jquery.min.js?v=2.1.4"></script> 91 <script src="css/static/js/bootstrap.min.js?v=3.3.6"></script> 92 <!-- 自定义js --> 93 <script src="css/static/js/content.js?v=1.0.0"></script> 94 <!-- iCheck --> 95 <script src="css/static/js/plugins/iCheck/icheck.min.js"></script> 96 <script> 97 $(document).ready(function () { 98 $('.i-checks').iCheck({ 99 checkboxClass: 'icheckbox_square-green', 100 radioClass: 'iradio_square-green', 101 }); 102 }); 103 </script> 104 </body> 105 </html>
1 <?php 2 use yii\helpers\Url; 3 ?> 4 <!DOCTYPE html> 5 <html> 6 <head> 7 <meta charset="utf-8"> 8 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 9 <title> - 基础表格</title> 10 <meta name="keywords" content=""> 11 <meta name="description" content=""> 12 <link rel="shortcut icon" href="favicon.ico"> <link href="css/static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet"> 13 <link href="css/static/css/font-awesome.css?v=4.4.0" rel="stylesheet"> 14 <link href="css/static/css/plugins/iCheck/custom.css" rel="stylesheet"> 15 <link href="css/static/css/animate.css" rel="stylesheet"> 16 <link href="css/static/css/style.css?v=4.1.0" rel="stylesheet"> 17 </head> 18 <body class="gray-bg"> 19 <div class="wrapper wrapper-content animated fadeInRight"> 20 <div class="row"> 21 <div class="col-sm-12"> 22 <div class="ibox float-e-margins"> 23 <div class="ibox-title"> 24 <h5>商品展示列表</h5> 25 <a href="<?=Url::to(['goods/goods_add'])?>"><button>添加商品</button></a> 26 </div> 27 <div class="ibox-content"> 28 <div class="row"> 29 <div class="col-sm-3"> 30 <div class="input-group"> 31 <input type="text" placeholder="请输入关键词" class="input-sm form-control"> <span class="input-group-btn"> 32 <button type="button" class="btn btn-sm btn-primary"> 搜索</button> </span> 33 </div> 34 </div> 35 </div> 36 <div class="table-responsive"> 37 <table class="table table-striped"> 38 <thead> 39 <tr> 40 <th></th> 41 <th>編號</th> 42 <th>商品名稱</th> 43 <th>商品分類</th> 44 <th>商品價格</th> 45 <th>商品庫存</th> 46 <th>商品狀態</th> 47 <th>添加時間</th> 48 <th colspan="2">操作</th> 49 </tr> 50 </thead> 51 <tbody> 52 <?php foreach ($data as $key=>$val){?> 53 <tr> 54 <td></td> 55 <td><?=$val['id']?></td> 56 <td><?=$val['name']?></td> 57 <td><?=$val['type_id']?></td> 58 <td><?=$val['price']?></td> 59 <td><?=$val['stock']?></td> 60 <td><?=$val['status']?'上架':'下架'?></td> 61 <td><?=date("Y-m-d",$val['addtime'])?></td> 62 <td><a href="<?=Url::to(['goods/goods_del','id'=>$val['id']])?>">刪除</a></td> 63 <td><a href="<?=Url::to(['goods/goods_update','id'=>$val['id']])?>">編輯</a></td> 64 </tr> 65 <?php }?> 66 </tbody> 67 </table> 68 </div> 69 </div> 70 </div> 71 </div> 72 </div> 73 </div> 74 <!-- 全局js --> 75 <script src="css/static/js/jquery.min.js?v=2.1.4"></script> 76 <script src="css/static/js/bootstrap.min.js?v=3.3.6"></script> 77 <!-- Peity --> 78 <script src="css/static/js/plugins/peity/jquery.peity.min.js"></script> 79 <!-- 自定义js --> 80 <script src="css/static/js/content.js?v=1.0.0"></script> 81 <!-- iCheck --> 82 <script src="css/static/js/plugins/iCheck/icheck.min.js"></script> 83 <!-- Peity --> 84 <script src="js/demo/peity-demo.js"></script> 85 <script> 86 $(document).ready(function () { 87 $('.i-checks').iCheck({ 88 checkboxClass: 'icheckbox_square-green', 89 radioClass: 'iradio_square-green', 90 }); 91 }); 92 </script> 93 </body> 94 </html>
1 <?php 2 use yii\helpers\Url; 3 ?> 4 <!DOCTYPE html> 5 <html> 6 7 <head> 8 9 <meta charset="utf-8"> 10 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 11 12 13 <title> - 基本表单</title> 14 <meta name="keywords" content=""> 15 <meta name="description" content=""> 16 17 <link rel="shortcut icon" href="favicon.ico"> <link href="css/static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet"> 18 <link href="css/static/css/font-awesome.css?v=4.4.0" rel="stylesheet"> 19 <link href="css/static/css/plugins/iCheck/custom.css" rel="stylesheet"> 20 <link href="css/static/css/animate.css" rel="stylesheet"> 21 <link href="css/static/css/style.css?v=4.1.0" rel="stylesheet"> 22 23 </head> 24 25 <body class="gray-bg"> 26 <div class="wrapper wrapper-content animated fadeInRight"> 27 28 29 <div class="row"> 30 <div class="col-sm-12"> 31 <div class="ibox float-e-margins"> 32 </div> 33 <div class="ibox-content"> 34 <form method="post" class="form-horizontal"> 35 <div class="form-group"> 36 <label class="col-sm-2 control-label">商品分類</label> 37 <div class="col-sm-10"> 38 <select class="form-control m-b" name="type_id"> 39 <option value="1">家電</option> 40 <option value="2">海鮮</option> 41 <option value="3">生鮮</option> 42 <option value="4">酒水</option> 43 </select> 44 </div> 45 </div> 46 <div class="hr-line-dashed"></div> 47 <div class="form-group"> 48 <label class="col-sm-2 control-label">商品名稱</label> 49 <div class="col-sm-10"> 50 <input type="text" class="form-control" name="name" value="<?=$data['name']?>"> 51 </div> 52 </div> 53 <div class="hr-line-dashed"></div> 54 <div class="form-group"> 55 <label class="col-sm-2 control-label">商品價格</label> 56 <div class="col-sm-10"> 57 <input type="text" class="form-control" name="price" value="<?=$data['price']?>"> 58 </div> 59 </div> 60 <div class="hr-line-dashed"></div> 61 <div class="form-group"> 62 <label class="col-sm-2 control-label">商品庫存</label> 63 <div class="col-sm-10"> 64 <input type="text" class="form-control" name="stock" value="<?=$data['stock']?>"> 65 </div> 66 </div> 67 <div class="hr-line-dashed"></div> 68 <div class="form-group"> 69 <label class="col-sm-2 control-label">商品分類</label> 70 <div class="col-sm-10"> 71 <div class="radio i-checks"> 72 <label> 73 <input type="radio" value="0" name="status"> <i></i>上架</label> 74 </div> 75 <div class="radio i-checks"> 76 <label> 77 <input type="radio" value="1" name="status"> <i></i>下架</label> 78 </div> 79 </div> 80 </div> 81 <div class="hr-line-dashed"></div> 82 <div class="form-group"> 83 <div class="col-sm-4 col-sm-offset-2"> 84 <button class="btn btn-primary" type="submit">修改</button> 85 <button class="btn btn-white" type="reset">重置</button> 86 </div> 87 </div> 88 </form> 89 </div> 90 </div> 91 </div> 92 </div> 93 <!-- 全局js --> 94 <script src="css/static/js/jquery.min.js?v=2.1.4"></script> 95 <script src="css/static/js/bootstrap.min.js?v=3.3.6"></script> 96 <!-- 自定义js --> 97 <script src="css/static/js/content.js?v=1.0.0"></script> 98 <!-- iCheck --> 99 <script src="css/static/js/plugins/iCheck/icheck.min.js"></script> 100 <script> 101 $(document).ready(function () { 102 $('.i-checks').iCheck({ 103 checkboxClass: 'icheckbox_square-green', 104 radioClass: 'iradio_square-green', 105 }); 106 }); 107 </script> 108 </body> 109 </html>