实例(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 15 PHP
php shell超强免杀、减少体积工具实现代码
Oct 16 PHP
PHP判断指定时间段的2个方法
Mar 14 PHP
8个PHP程序员常用的功能汇总
Dec 18 PHP
php隐藏实际地址的文件下载方法
Apr 18 PHP
WordPress中用于获取及自定义头像图片的PHP脚本详解
Dec 17 PHP
给PHP开发者的编程指南 第一部分降低复杂程度
Jan 18 PHP
php处理带有中文URL的方法
Jul 11 PHP
用HTML/JS/PHP方式实现页面延时跳转的简单实例
Jul 18 PHP
一键生成各种尺寸Icon的php脚本(实例)
Feb 08 PHP
laravel学习笔记之模型事件的几种用法示例
Aug 15 PHP
PHP中cookie知识点学习
May 06 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 开发工具
2006/12/06 PHP
php var_export与var_dump 输出的不同
2013/08/09 PHP
带密匙的php加密解密示例分享
2014/01/29 PHP
php准确获取文件MIME类型的方法
2015/06/17 PHP
PHP学习笔记之php文件操作
2016/06/03 PHP
2017年最好用的9个php开发工具推荐(超好用)
2017/10/23 PHP
Laravel 简单实现Ajax滚动加载示例
2019/10/22 PHP
YII2框架中日志的配置与使用方法实例分析
2020/03/18 PHP
共享自己写一个框架DreamScript
2007/01/20 Javascript
js 函数调用模式小结
2011/12/26 Javascript
jquery 通过name快速取值示例
2014/01/24 Javascript
jquery的attr方法禁用表单元素禁用输入内容
2014/06/23 Javascript
jquery实现九宫格大转盘抽奖
2015/11/13 Javascript
JS实现图片局部放大或缩小的方法
2016/08/20 Javascript
VueJS全面解析
2016/11/10 Javascript
BootStrap Validator对于隐藏域验证和程序赋值即时验证的问题浅析
2016/12/01 Javascript
详解vue-router2.0动态路由获取参数
2017/06/14 Javascript
Webpack如何引入bootstrap的方法
2017/06/17 Javascript
webpack 2.x配置reactjs基本开发环境详解
2017/08/08 Javascript
Angular4学习教程之HTML属性绑定的方法
2018/01/04 Javascript
JS中DOM元素的attribute与property属性示例详解
2018/09/04 Javascript
tensorflow查看ckpt各节点名称实例
2020/01/21 Python
PyTorch中Tensor的数据统计示例
2020/02/17 Python
Python 添加文件注释和函数注释操作
2020/08/09 Python
详解Anaconda安装tensorflow报错问题解决方法
2020/11/01 Python
利用python 下载bilibili视频
2020/11/13 Python
python简单实现插入排序实例代码
2020/12/16 Python
实例讲解CSS3中的box-flex弹性盒属性布局
2016/06/09 HTML / CSS
美国室内和室外装饰花盆购物网站:ePlanters
2019/03/22 全球购物
美国运动鞋类和服装零售连锁店:Shoe Palace
2019/08/13 全球购物
大学生应聘推荐信范文
2013/11/19 职场文书
初中高效课堂实施方案
2014/02/26 职场文书
医院党的群众路线教育实践活动学习心得体会
2014/10/30 职场文书
2014年班组工作总结
2014/11/20 职场文书
人民币使用说明书
2019/04/17 职场文书
英镑符号 £
2022/02/17 杂记