实例(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中使用ExcelFileParser处理excel获得数据(可作批量导入到数据库使用)
Aug 21 PHP
PHP设计模式 注册表模式(多个类的注册)
Feb 05 PHP
CI(CodeIgniter)框架中的增删改查操作
Jun 10 PHP
PHP网页游戏学习之Xnova(ogame)源码解读(三)
Jun 23 PHP
php采用curl实现伪造IP来源的方法
Nov 21 PHP
php树型类实例
Dec 05 PHP
PHP处理会话函数大总结
Aug 05 PHP
PHP入门教程之正则表达式基本用法实例详解(正则匹配,搜索,分割等)
Sep 11 PHP
PHP获取指定日期是星期几的实现方法
Nov 30 PHP
Laravel配置全局公共函数的方法步骤
May 09 PHP
在thinkphp5.0路径中实现去除index.php的方式
Oct 16 PHP
PHP ob缓存以及ob函数原理实例解析
Nov 13 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生成酷炫的四个字符验证码
2016/04/22 PHP
thinkphp5.1 框架导入/导出excel文件操作示例
2020/05/25 PHP
Laravel如何实现适合Api的异常处理响应格式
2020/06/14 PHP
Javascript实例教程(19) 使用HoTMetal(7)
2006/12/23 Javascript
JavaScript 组件之旅(四):测试 JavaScript 组件
2009/10/28 Javascript
JavaScript prototype对象的属性说明
2010/03/13 Javascript
JS trim去空格的最佳实践
2011/10/30 Javascript
ExtJS下书写动态生成的xml(兼容火狐)
2013/04/02 Javascript
js中call与apply的用法小结
2013/12/28 Javascript
IE与FireFox的JavaScript兼容问题解决办法
2013/12/31 Javascript
jQuery实用技巧必备(中)
2015/11/03 Javascript
jquery判断复选框选中状态以及区分attr和prop
2015/12/18 Javascript
angularJS+requireJS实现controller及directive的按需加载示例
2017/02/20 Javascript
基于Bootstrap table组件实现多层表头的实例代码
2017/09/07 Javascript
解决在vue项目中,发版之后,背景图片报错,路径不对的问题
2018/03/06 Javascript
Vue2(三)实现子菜单展开收缩,带动画效果实现方法
2019/04/28 Javascript
Vue 自定义指令功能完整实例
2019/09/17 Javascript
webpack HappyPack实战详解
2019/10/08 Javascript
Vue学习之常用指令实例详解
2020/01/06 Javascript
[01:02:46]VGJ.S vs NB 2018国际邀请赛小组赛BO2 第二场 8.18
2018/08/19 DOTA
python实现k均值算法示例(k均值聚类算法)
2014/03/16 Python
解决Python中由于logging模块误用导致的内存泄露
2015/04/23 Python
Python数据处理numpy.median的实例讲解
2018/04/02 Python
Python使用pymongo模块操作MongoDB的方法示例
2018/07/20 Python
用Python将Excel数据导入到SQL Server的例子
2019/08/24 Python
Python数据可视化处理库PyEcharts柱状图,饼图,线性图,词云图常用实例详解
2020/02/10 Python
工厂厂长的职责
2013/12/12 职场文书
初中同学聚会感言
2014/02/11 职场文书
学校读书活动总结
2014/06/30 职场文书
火锅店的活动方案
2014/08/15 职场文书
经典演讲稿开场白
2014/08/25 职场文书
正风肃纪剖析材料
2014/09/30 职场文书
学生检讨书范文
2014/10/30 职场文书
党支部考察鉴定意见
2015/06/02 职场文书
MySQL 可扩展设计的基本原则
2021/05/14 MySQL
mysql中数据库覆盖导入的几种方式总结
2022/03/25 MySQL