部分功能的实现
修改
case 'editnewsview' :
$id = $_REQUEST['id']; //获取修改id
$query = "select * from news where id='$id'";
$result = $db->query_exec($query);
$arr = $result->fetch_assoc();
$smarty->assign('page_title','新闻修改');
$smarty->assign('title',$arr['title']);
$smarty->assign('content',$arr['content']);
$smarty->assign('id',$arr['id']);//重点
editor('content',$arr['content']);//编辑器的内容
$smarty->assign('actionvalue','editnews');
$smarty->display('addnews.htm');
break;
case 'editnews' :
$title = $_REQUEST['title'];
$content = $_REQUEST['content'];
$id = $_REQUEST['id'];
$sql = "update news set title='$title', content='$content' , date=NOW() where id=$id ";
if($db->query_exec($sql))
{
echo "修改成功!<meta http-equiv=\"Refresh\" content=\"1; url=./index.php\">";
}
else echo "修改失败!<meta http-equiv=\"Refresh\" content=\"1; url=./index.php?action=editnewsview&id=$id\">";
$db->close();
break;
添加新闻
case 'addnewsview' :
$smarty->assign('page_title','新建新闻');
$smarty->assign('actionvalue','addnews');
editor('content',''); //调用编辑器,并定义文本域名为content(与下面addnews中的$_REQUEST['content']对应
$smarty->display('addnews.htm');
break;
case 'addnews' :
$title = $_POST['title'];
$content = $_POST['content'];
if(empty($title)|| empty($content))
{
echo "请填写完成!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php?action=addnewsview\">";
}
else
{
$sql = "insert into news(title,content,date) values('$title','$content', NOW())";//注意数据库的缺省
if($db->query_exec($sql))
{
echo "添加成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php\">";
}
else
{
echo "添加失败!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php?action=addnewsview\">";
}
}
$db->close();
break;
总结:
还有很多的不足,smarty的知识还要多多学习啊,差得远啊!