tp5-checkbox默认选中

标签: checkbox  默认选中  tp5

1.视图层

2.控制器

3.效果图如下

4.可复制代码如下:

<td>
     {volist name='auth_infoA' id='a'}
      <p style="margin-left: 20px">
       <input name="checkid" id="access_check" value="{$a.auth_id}" type="checkbox"
           {if condition = "in_array($a['auth_id'],$check)"}
              checked='checked'
           {/if}
        />{$a.auth_name}

      {volist name='auth_infoB' id='b'}
           {if condition="$a.auth_id eq $b.auth_pid" }
              <b id="$b.auth_pid" >
              <input  name="checkid" type="checkbox" value="{$b.auth_id}" style="margin-left: 20px;"
                   {if condition = "in_array($b['auth_id'],$check)"}
                        checked='checked'
                   {/if}
              >{$b.auth_name}
              </b>
           {/if}
      {/volist}
     </p>
    {/volist}                               
</td>
 public function role_update($role_id='',$role_name=''){
        $role_info = Db::name('role')
            ->find($role_id);
        $autharrid = explode(',',$role_info['role_auth_ids']);

        $auth_infoA = Db::name('auth')
            ->where('auth_level=0')
            ->select();
        $auth_infoB = Db::name('auth')
            ->where('auth_level=1')
            ->select();

        $this->assign('auth_infoA',$auth_infoA);
        $this->assign('auth_infoB',$auth_infoB);
        $this->assign(['id'=>$role_id,'rolename'=>$role_name,'check'=>$autharrid]);

        return $this->fetch('role/update');
    }