ajax实时任务提示功能的实现代码第1/2页

所属分类: 网络编程 / AJAX相关 阅读数: 1899
收藏 0 赞 0 分享
项目代码结构见 我之前写的[EXT/FCKEditor 集成 -- AJAX UI -- 一种web开发的新的思维,要及时转换思想]一文.
中的
├─taskofpig
│ ├─Controller
│ ├─Dao
│ ├─js
│ ├─music
│ ├─tpl
│ ├─tpl_c
│ └─_log
项目代码如下:
db.sql
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for task
-- ----------------------------
CREATE TABLE `task` (
`id` int(11) NOT NULL,
`title` varchar(100) collate utf8_unicode_ci NOT NULL,
`desc` text collate utf8_unicode_ci,
`date` datetime NOT NULL,
`created` int(11) default NULL,
`updated` int(11) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- ----------------------------
-- Table structure for task_seq
-- ----------------------------
CREATE TABLE `task_seq` (
`id` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/ucren/taskofpig/index.php
<?php
//设置正确的时区
date_default_timezone_set("Asia/Shanghai");
define('TASKOFPIG_DIR',dirname(__FILE__)) ;
require('../phplibs/FLEA/FLEA.php');
// 对$GLOBALS[G_FLEA_VAR]['CLASS_PATH'] 进行配置
FLEA::import(TASKOFPIG_DIR); //将当前目录加入到环境变量中
FLEA::loadAppInf('appConfig.php') ; //将配置文件单独分出来,容易维护
FLEA::init();
// 由于 FLEA_Db_TableDataGateway 并不是自动载入的,因此需要明确载入
FLEA::loadClass('FLEA_Db_TableDataGateway');
FLEA::runMVC();
?>
/ucren/taskofpig/appConfig.php
<?php
// 对 $GLOBALS[G_FLEA_VAR]['APP_INF'] 进行配置
return array(
'dispatcher' => 'FLEA_Dispatcher_Simple' , //定制调度器 FLEA_Dispatcher_Auth
'controllerAccessor' => 'ctl' ,
'actionAccessor' => 'act' ,
'view' => 'FLEA_View_Smarty', //定制视图
'viewConfig' => array(
'smartyDir' => '../phplibs/Smarty',
'template_dir' => './tpl',
'compile_dir' => './tpl_c',
'left_delimiter' => '<%',
'right_delimiter' => '%>',
'debugging' => false
),
'dbDSN' => array( //定制数据库连接参数
'driver' => 'mysql',
'host' => 'localhost',
'login' => 'dbuser',
'password' => 'dbpass',
'database' => 'dbname' ,
'charset ' => 'utf8'
) ,
'logFileDir' => './log' , //定制日志
'logFilename' => 'task_admin.log'
);
?>
/ucren/taskofpig/Dao/Table.php
<?php
//生气猪的任务计划表
class Dao_TaskTable extends FLEA_Db_TableDataGateway
{
// 指定数据表名称
var $tableName = 'task';
// 指定主键字段名
var $primaryKey = 'id';
}
?>
/ucren/taskofpig/Controller/Default.php
<?php
FLEA::loadFile('Dao_Table.php',true) ;
FLEA::loadFile('FLEA_Ajax_JSON.php',true) ;
class Controller_Default extends FLEA_Controller_Action
{
var $smarty ;
function Controller_Default()
{
$this->smarty = $this->_getView();
$this->smarty->assign('sitename','任务计划表 -- 生气猪') ;
$this->smarty->assign('opname','任务列表') ;//缺省应该在子模块中更改值
}
function actionIndex()
{
$this->toModulePage(); //缺省显示任务列表页
}
//定义一个函数用于调用FCKeditor
function call_fck($input_name,$input_value,$w='800',$h='400')
{
include_once '../fckeditor/fckeditor.php';
$fcked = new FCKeditor($input_name) ;
$fcked->BasePath = '../fckeditor/';
$fcked->ToolbarSet = 'Default' ; //工具栏设置
$fcked->InstanceName = $input_name ;
$fcked->Width = $w;
$fcked->Height = $h;
$fcked->Value = $input_value;
$fck_area = $fcked->CreateHtml();
$this->smarty->assign('fck_area',$fck_area);
unset($fck_area) ;
unset($fcked) ;
}
function _showPage($tpl='taskofpig.main.html')
{
$this->smarty->display($tpl);
}
function actionAdd()
{
$this->addTask();
}
function actionUpdate()
{
$this->updateTask();
}
function deleteTask($id){
$row = array('id'=>$id);
$thisDao = & new Dao_TaskTable() ;
$status = $thisDao->remove($row); //返回boolean值
unset($thisDao);
return $status ;
}
function listTask()
{
$thisDao = & new Dao_TaskTable() ;
$rows = $thisDao->findAll(); //二维数组
foreach($rows as &$row) //注意这里要传引用
{
$row['desc'] = mb_substr($row['desc'],0,40,'UTF-8');
}
$this->smarty->assign('rowSet',$rows);
$this->_showPage();
}
function addTask()
{
$thisDao = & new Dao_TaskTable() ;
$row = array(
'title' => $_REQUEST['title'],
'desc' => $_REQUEST['desc'],
'date' => $_REQUEST['date']
);
$commitId = $thisDao->create($row);
unset($thisDao);
echo "成功添加新任务";
redirect( url("Default"),1) ;
}
function updateTask()
{
$thisDao = & new Dao_TaskTable() ;
$row = array(
'id' => $_REQUEST['id'],
'title' => $_REQUEST['title'],
'desc' => $_REQUEST['desc'],
'date' => $_REQUEST['date']
);
$commitId = $thisDao->update($row);
unset($thisDao);
echo "成功更新任务";
redirect( url("Default"),1) ;
}
function queryTask($id){
$thisDao = & new Dao_TaskTable() ;
$row = $thisDao->find(array('id'=>$id));
unset($thisDao);
return $row ;
}
function queryTaskForDate($date=null)
{
$thisDao = & new Dao_TaskTable() ; //'2008-08-17 07:42:29'
$row = $thisDao->find(array('date'=>date('Y-m-d H:i:s')));
unset($thisDao);
if (!empty($row))
{
$jsonobj = new Services_JSON();
echo $jsonobj->encode($row);
}
else
die(date('Y-m-d H:i:s'));
}
//任务流转控制方法
function toModulePage()
{
if ($_REQUEST['op'] == 'search') {
$this->queryTaskForDate();
}
else if ($_REQUEST['op'] == 'add') {
$this->smarty->assign('opname','添加新任务') ;
$this->smarty->assign('taskTime',date('Y-m-d H:i:s')) ;
$this->call_fck('desc','');
$this->_showPage('taskofpig.add.html');
}
else if ($_REQUEST['op'] == 'del') {
if ( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) )
$status = $this->deleteTask($_REQUEST['id']) ;
$this->listTask();
}
else if ($_REQUEST['op'] == 'edit') {
if ( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) ){
$row = $this->queryTask($_REQUEST['id']) ;
}
$this->call_fck('desc',$row['desc']);
unset($row['desc']) ;
$this->smarty->assign('rowSet',$row);
$this->smarty->assign('opname','修改任务') ;
$this->_showPage('taskofpig.edit.html');
}
else { //列表
$this->listTask();
}
}
}
?>
更多精彩内容其他人还在看

ajax和jsonp跨域的原理本质详解

跨域问题是我们在开发中经常会遇到的一个需求,下面这篇文章主要给大家介绍了关于ajax和jsonp跨域的原理本质,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
收藏 0 赞 0 分享

ajax获取json数据为undefined原因分析

Ajax 允许在不干扰 Web 应用程序的显示和行为的情况下在后台进行数据检索。这篇文章主要介绍了ajax获取json数据为undefined--原因,需要的朋友可以参考下
收藏 0 赞 0 分享

ajax实现用户名校验的传统和jquery的$.post方式(实例讲解)

下面小编就为大家分享一篇ajax实现用户名校验的传统和jquery的$.post方式的实例讲解,具有很好的参考价值,希望对大家有所帮助
收藏 0 赞 0 分享

ajax中用josnp接收josn数据的实现方法

下面小编就为大家分享一篇ajax中用josnp接收josn数据的实现方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

ajax跨域获取网站json数据的实例

下面小编就为大家分享一篇ajax跨域获取网站json数据的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

关于前端ajax请求的优雅方案(http客户端为axios)

这篇文章主要给大家介绍了关于前端ajax请求的优雅方案,本文http客户端为axios,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
收藏 0 赞 0 分享

快速解决ajax请求出错状态码为0的问题

下面小编就为大家分享一篇快速解决ajax请求出错状态码为0的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

ajax实现改变状态和删除无刷新的实例

下面小编就为大家分享一篇ajax实现改变状态和删除无刷新的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

ajax结合mysql数据库和smarty实现局部数据状态的刷新方法

下面小编就为大家分享一篇ajax结合mysql数据库和smarty实现局部数据状态的刷新方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Ajax客户端异步调用服务端的实现方法(js调用cs文件)

下面小编就为大家分享一篇Ajax客户端异步调用服务端的实现方法(js调用cs文件),具有很好的参考价值,希望对大家有所帮助
收藏 0 赞 0 分享
查看更多