实例(Smarty+FCKeditor新闻系统)


Posted in PHP onJanuary 02, 2007

以下是主文件index.php的内容:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
<?php  
require('./global.php');  
require('./smarty/libs/Smarty.class.php');  
require('./mysql.php');  
require('./FCKeditor/fckeditor.php');  
$action=$_REQUEST['action'];  
//定义一个函数用于调用FCK  
function editor($input_name, $input_value)  
{  
global $smarty;  
$editor = new FCKeditor($input_name) ;  
$editor->BasePath   = "./FCKeditor/";//指定编辑器路径  $editor->ToolbarSet = "Default";//编辑器工具栏有Basic(基本工具),Default(所有工具)选择  
$editor->Width      = "100%";  
$editor->Height     = "320";  
$editor->Value      = $input_value;  
$editor->Config['AutoDetectLanguage'] = true ;  
$editor->Config['DefaultLanguage']  = 'en' ;//语言  
$FCKeditor = $editor->CreateHtml();  
$smarty->assign("editor", $FCKeditor);//指定区域  
}  
switch ($action){  
case 'addnewsview':  
        $smarty= new Smarty();  
        $smarty->template_dir = './template';  
        $smarty->compile_dir = './smarty/templates_c';  
        $smarty->assign('page_title','新建新闻');  
        $smarty->assign('actionvalue','addnews');  
        editor('content','');//调用编辑器,并定义文本域名为content(与下面addnews中的$_REQUEST['content']对应  
        $smarty->display('addnews.htm');  
break;  
case 'addnews':  
        $title=$_REQUEST['title'];  
        $content=$_REQUEST['content'];  
        $db=new mysql();  
        $button=$_REQUEST['Submit'];  
        if(empty($title) || empty($content)){  
        echo "请填写完成!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php?action=addnewsview\">";  
        }else{  
                $sql="insert into news values(id,'admin','$title','$content',NOW())";  
                $db->query_exec($sql);  
        echo "操作成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php\">";  
        }  
break;  
case 'editnewsview':  
        $smarty= new Smarty();  
        $smarty->template_dir = './template';  
        $smarty->compile_dir = './smarty/templates_c';  
        $smarty->assign('page_title','修改新闻');  
        $smarty->assign('actionvalue','addnews');  
        $id=$_REQUEST['id'];  
        $query="select * from news where id=$id";  
        $db=new mysql();  
        $result = $db->query_exec($query);  
        $rs = $result-> fetch_assoc();  
        $smarty->assign('title',$rs['title']);  
        //$smarty->assign('content',$rs['content']);  
        $smarty->assign('actionvalue','editnews');  
        $smarty->assign('id',$rs['id']);  
        editor('content',$rs['content']);  
        $smarty->display('addnews.htm');  
break;  
case 'editnews':  
        $title=$_REQUEST['title'];  
        $content=$_REQUEST['content'];  
        $id=$_REQUEST['id'];  
        $button=$_REQUEST['Submit'];  
        $db=new mysql();  
        if ($button=='提交'){  
                $sql="update news set title='$title',content='$content',date=NOW() where id=$id";  
                $db->query_exec($sql);  
        echo "操作成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php\">";  
        }  
break;  
case 'delnews':  
        $db=new mysql();  
        if ($checkbox!="" or count($checkbox)!=0) {  
                for ($i=0;$i<count($checkbox);$i++){  
                        $db->query_exec("delete from news where id='$checkbox[$i]'");  
                }  
        }  
        echo "操作成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php\">";  
break;  
default:  
        $smarty= new Smarty();  
        $smarty->template_dir = './template';  
        $smarty->compile_dir = './smarty/templates_c';  
        $smarty->assign('page_title','新闻管理');  
        $smarty->assign('actionvalue','delnews');  
        $query="select * from news";  
        $db=new mysql();  
        $result = $db->query_exec($query);  
        while ($rs = $result-> fetch_assoc()) {  
                $array[]= array("id"=>$rs['id'], "title"=>$rs['title'],"date"=>$rs['date']);   
                $smarty->assign('news',$array);  
        }  
        $smarty->display('index.htm');  
}  
?>  
以下是模板文件index.htm的内容  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
"http://www.w3.org/TR/html4/loose.dtd">  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
<title>{$page_title}</title>  
</head>  
<body>  
<p class="style1">新闻管理</p>  
<hr>  
<table width="771" height="115" border="0">  
  <tr>  
    <td height="62"><div align="center">系统管理</div></td>  
    <td width="666" rowspan="2"><form name="form1" method="post" action="">  
      <table width="543" border="0">  
        <tr>  
          <td width="253">标题</td>  
          <td width="230">日期</td>  
          <td width="46">选择</td>  
        </tr>  
                {section name=news loop=$news}   
        <tr>  
          <td><a href="./index.php?action=editnewsview&id={$news[news].id}">{$news[news].title}</a></td>  
          <td>{$news[news].date}</td>  
          <td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="{$news[news].id}"></td>  
        </tr>  
                {/section}  
      </table>  
      <p>  
        <input type="submit" name="Submit" value="删除">  
      <input name="action" type="hidden" id="action" value="{$actionvalue}">  
          </p>  
    </form> </td>  
  </tr>  
  <tr>  
    <td width="95" height="47"><div align="center"><a href="./index.php?action=addnewsview">添加新闻</a></div></td>  
  </tr>  
</table>  
<p class="style1"> </p>  
</body>  
</html>  
以下是添加新闻的模板文件addnews.htm  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
"http://www.w3.org/TR/html4/loose.dtd">  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
<link href="./css/a.css" rel="stylesheet" type="text/css">  
<title>{$page_title}</title>  
</head>  
<body>  
<p class="style1">新闻管理登陆 </p>  
<hr>  
<table width="771" height="501" border="0">  
  <tr>  
    <td height="62"><div align="center">系统管理</div></td>  
    <td width="666" rowspan="2"><form name="form1" method="post" action="index.php">  
      <p>标题  
          <input name="title" type="text" id="title" value="{$title}">  
</p>  
      <p>内容:</p>  
      <p>{$editor}</p>  
      <p>  
        <input type="submit" name="Submit" value="提交">   
                <input type="hidden" name='action' value={$actionvalue}>  
                <input name="id" type="hidden" value="{$id}">   
                </p>  
    </form>  
        </td>  
  </tr>  
  <tr>  
    <td width="95" height="433"><div align="center">添加新闻</div></td>  
  </tr>  
</table>  
</body>  
</html> 

注:数据库已经在附件里面,先新建一个名为new的数据库,再把表导入
本系统用户名:admin    密码:admin
打包下载
实例(Smarty+FCKeditor新闻系统)下载此文件

PHP 相关文章推荐
提升PHP速度全攻略
Oct 09 PHP
第十一节--重载
Nov 16 PHP
精通php的十大要点(上)
Feb 04 PHP
解析isset与is_null的区别
Aug 09 PHP
PHP取整函数:ceil,floor,round,intval的区别详细解析
Aug 31 PHP
PHP根据IP判断地区名信息的示例代码
Mar 03 PHP
destoon实现调用图文新闻的方法
Aug 21 PHP
PHP微信支付实例解析
Jul 22 PHP
YII2框架中使用yii.js实现的post请求
Apr 09 PHP
PHP Trait代码复用类与多继承实现方法详解
Jun 17 PHP
PHP实现递归的三种方法
Jul 04 PHP
php远程请求CURL实例教程(爬虫、保存登录状态)
Dec 10 PHP
PHP+JS无限级可伸缩菜单详解(简单易懂)
Jan 02 #PHP
PHP文件上传实例详解!!!
Jan 02 #PHP
AJAX for PHP简单表数据查询实例
Jan 02 #PHP
[原创]PHP中通过ADODB库实现调用Access数据库之修正版本
Dec 31 #PHP
PHP中通过ADO调用Access数据库的方法测试不通过
Dec 31 #PHP
刚才在简化php的库,结果发现很多东西
Dec 31 #PHP
smarty+adodb+部分自定义类的php开发模式
Dec 31 #PHP
You might like
PHP中usort在值相同时改变原始位置问题的解决方法
2011/11/27 PHP
php5.5新数组函数array_column使用
2013/07/08 PHP
php如何连接sql server
2015/10/16 PHP
javascript Split方法,indexOf方法、lastIndexOf 方法和substring 方法
2009/03/21 Javascript
Javascript 调试利器 Firebug使用详解六
2009/07/05 Javascript
基于jquery的关于动态创建DOM元素的问题
2010/12/24 Javascript
javascript在子页面中函数无法调试问题解决方法
2014/01/17 Javascript
javascript获取当前鼠标坐标的方法
2015/01/10 Javascript
jQuery通过ajax请求php遍历json数组到table中的代码(推荐)
2016/06/12 Javascript
jquery siblings获取同辈元素用法实例分析
2016/07/25 Javascript
VueJs路由跳转——vue-router的使用详解
2017/01/10 Javascript
jQuery实用密码强度检测
2017/03/02 Javascript
基于vue实现多引擎搜索及关键字提示
2017/03/16 Javascript
Vue shopCart 组件开发详解
2018/01/26 Javascript
详解plotly.js 绘图库入门使用教程
2018/02/23 Javascript
Windows下支持自动更新的Electron应用脚手架的方法
2018/12/24 Javascript
vue之a-table中实现清空选中的数据
2019/11/07 Javascript
[56:35]DOTA2上海特级锦标赛C组小组赛#1 OG VS Archon第二局
2016/02/27 DOTA
[59:35]DOTA2上海特级锦标赛主赛事日 - 3 败者组第三轮#1COL VS Alliance第二局
2016/03/04 DOTA
python下如何让web元素的生成更简单的分析
2008/07/17 Python
python使用Berkeley DB数据库实例
2014/09/26 Python
Python IDE PyCharm的基本快捷键和配置简介
2015/11/04 Python
Python中文分词实现方法(安装pymmseg)
2016/06/14 Python
Python中的单行、多行、中文注释方法
2018/07/19 Python
python实现时间o(1)的最小栈的实例代码
2018/07/23 Python
Python一键查找iOS项目中未使用的图片、音频、视频资源
2019/08/12 Python
Python进度条的制作代码实例
2019/08/31 Python
python3下pygame如何实现显示中文
2020/01/11 Python
阿玛尼美国官方网站:Armani.com
2016/11/25 全球购物
全球最大的房车租赁市场:Outdoorsy
2018/09/19 全球购物
20岁生日感言
2014/01/13 职场文书
运动会入场词60字
2014/02/15 职场文书
珍惜资源的建议书
2014/08/26 职场文书
导游词之泰山玉皇顶
2019/12/23 职场文书
CSS 制作波浪效果的思路
2021/05/18 HTML / CSS
详细介绍python类及类的用法
2021/05/31 Python