|
发表于 2008-8-11 10:58:28
|
显示全部楼层
model:
PHP复制代码 /**
*删除新闻
*用法:deleteNews()
*/
function deleteNews ($id)
{
//删除单条新闻
if($id!=0)
{
//$this->db->where('id',(int)$id);
//$this->db->delete('news');
$this->db->delete('news', array('id' => $id));
return true;
}
//批量删除新闻
else
{
$this->db->where_in('id',$this->input->post('id'));
$this->db->delete('news');
return true;
}
}
复制代码
controller:
PHP复制代码
function deleteNews ($id=0)
{
if (!$this->session->userdata("admin"))
{
redirect ("admin/login");
}
isset($id) ? $id = (int )$id : $id = 0;
$this->News_model->deleteNews($id);
redirect ("admin/listnews");
}
复制代码
views:
HTML复制代码
<?php foreach ($news->result() as $row) :?>
<TR>
<TD class="altbg1" width="5%">
<input name="id[]" type="checkbox" id="id[]" value="<?php echo $row->id ?>"> </TD>
<TD width="80%"><a href="<?php echo site_url("news/readnews") ."/". $row->id; ?>" target="_blank"> <?php echo $row->title ?> </a></TD>
<TD width="5%"><a href="<?php echo site_url("admin/editnews") ."/". $row->id; ?>">编辑 </a> </TD>
<TD width="5%"><a href="<?php echo site_url("admin/deletenews") ."/". $row->id; ?>" onClick="return(confirm('删除后不可恢复,确定删除?'))">删除 </a></TD>
</TR>
<?php endforeach ?>
<TR>
<TD colspan="4">
<input type="submit" name="submit" id="submit" value="删除选定新闻" onClick="return(confirm('删除后不可恢复,确定删除?'))">
</TD>
</TR> 复制代码
希望对你有所帮助 |
评分
-
查看全部评分
|