实例(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 随机生成10位字符代码
Mar 26 PHP
php面向对象全攻略 (十七) 自动加载类
Sep 30 PHP
php学习笔记 PHP面向对象的程序设计
Jun 13 PHP
PHP获取和操作配置文件php.ini的几个函数介绍
Jun 24 PHP
解析PHP中的file_get_contents获取远程页面乱码的问题
Jun 25 PHP
PHP 获取远程文件大小的3种解决方法
Jul 11 PHP
调整PHP的性能
Oct 30 PHP
PHP中使用register_shutdown_function函数截获fatal error示例
Apr 21 PHP
laravel 中如何使用ajax和vue总结
Aug 16 PHP
php使用pecl方式安装扩展操作示例
Aug 12 PHP
laravel-admin 实现在指定的相册下添加照片
Oct 21 PHP
Laravel手动返回错误码示例
Oct 22 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 ignore_user_abort与register_shutdown_function 使用方法
2009/06/14 PHP
CodeIgniter删除和设置Cookie的方法
2015/04/07 PHP
刷新PHP缓冲区为你的站点加速
2015/10/10 PHP
javascript学习笔记(十七) 检测浏览器插件代码
2012/06/20 Javascript
基于jquery的滚动条滚动固定div(附演示下载)
2012/10/29 Javascript
js验证身份证号有效性并提示对应信息
2015/10/19 Javascript
Jquery实现仿京东商城省市联动菜单
2015/11/19 Javascript
全面解析Bootstrap排版使用方法(文字样式)
2015/11/30 Javascript
基于JS分页控件实现简单美观仿淘宝分页按钮效果
2016/11/07 Javascript
浅析vue component 组件使用
2017/03/06 Javascript
AngularJs ng-change事件/指令的用法小结
2017/11/01 Javascript
常用的9个JavaScript图表库详解
2017/12/19 Javascript
js判断节假日实例代码
2017/12/27 Javascript
JS装饰器函数用法总结
2018/04/21 Javascript
详解angular路由高亮之RouterLinkActive
2018/04/28 Javascript
浅谈Angular HttpClient简单入门
2018/05/04 Javascript
js中值引用和地址引用实例分析
2019/06/21 Javascript
五分钟搞懂Vuex实用知识(小结)
2019/08/12 Javascript
javascript 数组(list)添加/删除的实现
2020/12/17 Javascript
讲解Python中的标识运算符
2015/05/14 Python
Python3实现获取图片文字里中文的方法分析
2018/12/13 Python
pycharm设置鼠标悬停查看方法设置
2019/07/29 Python
Python 中的 global 标识对变量作用域的影响
2019/08/12 Python
python数据类型之间怎么转换技巧分享
2019/08/20 Python
Python大数据之网络爬虫的post请求、get请求区别实例分析
2019/11/16 Python
基于Python获取docx/doc文件内容代码解析
2020/02/17 Python
python+selenium+Chrome options参数的使用
2020/03/18 Python
Python web如何在IIS发布应用过程解析
2020/05/27 Python
浅谈TensorFlow中读取图像数据的三种方式
2020/06/30 Python
分享PyCharm最新激活码(真永久激活方法)不用每月找安装参数或最新激活码了
2020/12/27 Python
使用css实现android系统的loading加载动画
2019/07/25 HTML / CSS
荷兰牛仔裤网上商店:Jeans Centre
2018/04/03 全球购物
美国婴儿用品及配件购买网站:Munchkin
2019/04/03 全球购物
小学教师节活动方案
2014/01/31 职场文书
小学教师听课制度
2014/02/01 职场文书
2015年公民道德宣传日活动总结
2015/03/23 职场文书