用set_checkbox的时候碰到问题,请会使的帮我看看
本帖最后由 saixs 于 2011-11-25 08:49 编辑控制器代码:
/* 修改用户*/
function edit_user()
{
//验证是否有权限访问
check_limits_page($this->session->userdata('limits'),'41');
$data['get_user_name'] = $this->Madmin->get_user_name($this->uri->segment(3));
$data['limits1'] = array(
array('权限设定'),
array('广告管理中心','广告管理','所有广告','广告初审权限','广告终审权限','广告修改'),
array('广告位管理中心','广告位管理'),
array('站点管理中心','站点管理'),
array('用户管理中心','用户管理'),
array('IP记录查看','IP记录查看'),
array('JS组管理中心','JS组管理'),
array('是否业务员','业务员')
);
$this->load->view('admin/edit_user', $data);
}
/* 修改用户后台*/
function edit_user_ok()
{
//验证是否有权限访问
check_limits_page($this->session->userdata('limits'),'41');
//验证表单
$this->form_validation->set_rules('password', '密码', 'required|min_length|is_alpha');
$this->form_validation->set_rules('limits[]');
$this->form_validation->set_rules('id');
$this->form_validation->set_message('min_length', '%s长度必须超过6位.');
$this->form_validation->set_message('required', '%s不能为空.');
$this->form_validation->set_error_delimiters('<span>', '</span>');
if ($this->form_validation->run() == FALSE)
{
//验证失败则返回
$data['get_user_name'] = $this->Madmin->get_user_name($this->input->post('id'));
$data['limits1'] = array(
array('权限设定'),
array('广告管理中心','广告管理','所有广告','广告初审权限','广告终审权限','广告修改'),
array('广告位管理中心','广告位管理'),
array('站点管理中心','站点管理'),
array('用户管理中心','用户管理'),
array('IP记录查看','IP记录查看'),
array('JS组管理中心','JS组管理'),
array('是否业务员','业务员')
);
$this->load->view('admin/edit_user',$data);
}
else
{
//获取权限字段信息,连成字符串
$limits = $this->input->post('limits');
for ($i=0; $i < count($limits); $i++)
{
if ($i==0)
{
$str=$limits[$i];
}
else
{
$str=$str.','.$limits[$i];
}
}
$arr['limits'] = $str;
if ($this->input->post('password')<>$this->input->post('password1'))
{
$arr['password'] = md5($this->input->post('password'));
}
$where['id'] = $this->input->post('id');
$table = 'admin';
$res = $this->db->update($table, $arr, $where);
//判断操作是否成功进行想在应跳转
if ($res)
{
showmessage('修改用户信息成功', $this->session->userdata('uri'));
}
else
{
showmessage('操作失败,系统繁忙或着填写错误', $this->session->userdata('uri'));
}
}
}
<html>
<head>
<base href="<?php echo base_url() ;?>"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>修改用户信息</title>
<link rel="stylesheet" type="text/css" href="skin/css/base.css">
<script type="text/javascript" src="js/calendar.js"></script>
</head>
<body leftmargin="8" topmargin="8" background='skin/images/allbg.gif'>
<!--快速转换位置按钮-->
<table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D1DDAA" align="center">
<tr>
<td height="26" background="skin/images/newlinebg3.gif">
<table width="98%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td align="center">
<?php echo anchor('admin/user_list','返回用户列表')?>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!--内容列表 -->
<form method="post" action="<?php echo site_url('admin/edit_user_ok')?>">
<?php foreach ($get_user_name as $row):?>
<input type="hidden" name="id" value="<?php echo $row->id?>">
<input type="hidden" name="password1" value="<?php echo $row->password?>">
<table width="98%" border="0" cellpadding="3" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px">
<tr bgcolor="#E7E7E7">
<td height="30" colspan="2" background="skin/images/tbg.gif"> 修改用户信息 </td>
</tr>
<tr bgcolor="#FAFAF1" height="30">
<td align="right" width="20%">用户名:</td>
<td align="left"><input type="text" style="width:400px;" name="username" id="username" value="<?php echo $row->user_name?>" disabled></td>
</tr>
<tr bgcolor="#FAFAF1" height="30">
<td align="right">密码:</td>
<td align="left"><input type="text" style="width:400px;" name="password" id="password" value="<?php
if( set_value('password')<>'')
{
echo set_value('password');
}else{
echo $row->password;
}?>"><?php echo form_error('password'); ?></td>
</tr>
<tr bgcolor="#FAFAF1" height="30">
<td align="right">权限:</td>
<td align="left"><table>
<?php //从多维数组中读取权限相关数据
for ($i=1;$i<count($limits1);$i++):
echo "<tr><td align=right height=25>";
for ($j=0;$j<count($limits1[$i]);$j++):
if ($j==0)
{
echo $limits1[$i][$j].":</td><td>";
}
else
{
echo "<input type='checkbox' name='limits[]' value='".$i.$j."'";
if (set_value('limits[]')<>'')
{
echo set_checkbox('limits[]', $i.$j);
}
else
{
if (strpos($row->limits,$i.$j)>-1)
{
echo 'checked';
}
}
echo " /> ".$limits1[$i][$j];
}
endfor;
echo "</td></tr>";
endfor;?></table>
</td>
</tr>
<tr bgcolor="#FAFAF1" height="30">
<td align="right" ></td>
<td align="left" ><input type="submit" name="submit_site" value="修改"/></td>
</tr>
</table>
<?php endforeach;?>
</form>
</body>
</html>
修改读数据库数据的时候是好的,当修改密码,密码验证出问题返回后原先选的就对不上了。。。不晓得哪里有问题。已经被困好久了,请各位大大帮着看看
在添加用户的时候验证返回后是正确的<?php//从多维数组中读取权限相关数据
for ($i=1;$i<count($limits);$i++):
echo "<tr><td align=right height=25>";
for ($j=0;$j<count($limits[$i]);$j++):
if ($j==0)
{
echo $limits[$i][$j].":</td><td>";
}
else
{
echo "<input type='checkbox' name='limits[]' value='".$i.$j."'".set_checkbox('limits[]', $i.$j)." /> ".$limits[$i][$j];
}
endfor;
echo "</td></tr>";
endfor;?>
数据库里用户表权限项的内容形式是这样的:11,12,13,14,15,21,31,41,51,61,71 刚又做了个测试,把判断提到for外面就成功了
<?php //从多维数组中读取权限相关数据
if (set_value('id')<>'')
{
for ($i=1;$i<count($limits1);$i++):
echo "<tr><td align=right height=25>";
for ($j=0;$j<count($limits1[$i]);$j++):
if ($j==0)
{
echo $limits1[$i][$j].":</td><td>";
}
else
{
echo "<input type='checkbox' name='limits[]' value='".$i.$j."'";
echo set_checkbox('limits[]', $i.$j);
echo " /> ".$limits1[$i][$j];
}
endfor;
echo "</td></tr>";
endfor;
}
else
{
for ($i=1;$i<count($limits1);$i++):
echo "<tr><td align=right height=25>";
for ($j=0;$j<count($limits1[$i]);$j++):
if ($j==0)
{
echo $limits1[$i][$j].":</td><td>";
}
else
{
echo "<input type='checkbox' name='limits[]' value='".$i.$j."'";
if (strpos($row->limits,$i.$j)>-1)
{
echo 'checked';
}
echo " /> ".$limits1[$i][$j];
}
endfor;
echo "</td></tr>";
endfor;
}
?>
这和前面的有啥区别啊。。。。
<?php //从多维数组中读取权限相关数据
for ($i=1;$i<count($limits1);$i++):
echo "<tr><td align=right height=25>";
for ($j=0;$j<count($limits1[$i]);$j++):
if ($j==0)
{
echo $limits1[$i][$j].":</td><td>";
}
else
{
echo "<input type='checkbox' name='limits[]' value='".$i.$j."'";
if (set_value('limits[]')<>'')
{
echo set_checkbox('limits[]', $i.$j);
}
else
{
if (strpos($row->limits,$i.$j)>-1)
{
echo 'checked';
}
}
echo " /> ".$limits1[$i][$j];
}
endfor;
echo "</td></tr>";
endfor;?> 感谢楼主的分享啊!
页:
[1]