添加用户的Ajax接口: addUser.php
<?php
require_once './bussiness.php';/**
 * 添加用户ajax请求
 */
return addUser($_POST['name']);
?>删除用户的ajax接口: delUser.php
<?php
require_once './bussiness.php';/**
 * 删除用户ajax请求
 */
return deleteUser($_POST['id']);
?>提交订餐项的ajax接口: submitItem.php
<?php
require_once './bussiness.php';$userId = $_POST['userId'];
$food = $_POST['food'];
$t = $_POST['t'];/**
 * 提交一个订餐请求的ajax地址
 */
echo (string)addItem($userId, $food, $t);
?>展现订餐项的视图: viewItems.php
<?php
/**
 * 展现某个订餐时间的所有订餐项
 */
require_once './bussiness.php';
$t = $_GET['t'];
$year = date('Y', $t);
$month = date('n', $t);
$day = date('j', $t);
$hour = (date('G', $t) + 8) % 24;
$flag = $hour < 13;
$items = getItemsByTime($year, $month, $day, $flag);
$users = getUsers();
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<table cellspacing="0">
<tr>
<th colspan="7">谁填谁的, 填完"吃啥"点下后面的"就吃这个"</th>
</tr>
<tr align="center">
<td>名字</td>
<td>吃啥</td>
<td>操作</td>
<td>分水岭</td>
<td>名字</td>
<td>吃啥</td>
<td>操作</td>
</tr>
<?php 
foreach($users as $index => $user) {
if($index % 2 !== 0) continue;
?>
<tr class="ctrl-record" userId="<?php echo $user->getId(); ?>">
<td><?php echo iconv('gbk', 'utf-8', $user->getName()); ?></td>
<td><input class="food-input ctrl-food-input" type="text" value="<?php echo $items[$user->getId()] ? $items[$user->getId()]->getFood() : '&nbsp;'; ?>"></td>
<td><button class="ctrl-submit">就吃这个</button></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-|分|-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><?php if($users[$index + 1]) echo iconv('gbk', 'utf-8', $users[$index + 1]->getName()); else echo '&nbsp;'; ?></td>
<td><input class="food-input ctrl-food-input" type="text" value="<?php if($users[$index + 1]) echo $items[$users[$index + 1]->getId()] ? $items[$users[$index + 1]->getId()]->getFood() : '&nbsp;'; else echo '&nbsp;'; ?>"></td>
<td><button class="ctrl-submit">就吃这个</button></td>
</tr>
<?php
}
?>
</table>展现所有用户的视图: viewUsers.php
<?php
require_once './bussiness.php';/**
 * 系统中用户的管理界面
 * @author selfimpr
 * @blog http://blog.csdn.net/lgg201
 * @email [email protected]
 */$users = getUsers();
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<input type="text" id="new_user_input" onkeyup="javascript: event.keyCode == 13 && $('#new_user').click();" /><button id="new_user">新增</button>
<?php 
if(empty($users)) return ;
?>
<div style="width: 300px; clear: both;">
<?php 
foreach($users as $index => $user) {
?>
<div class="ctrl-record" style="width: 120px; padding: 10px; height: 70px; border: 1px solid #808080; background: #E8E8E8; float: left; display: block; margin: 5px;" userId="<?php echo $user->getId(); ?>">
<input type="text" value="<?php echo iconv('gbk', 'utf-8', $user->getName()); ?>" style="display: block; width: 100px; height: 20px; line-height: 20px;"/>
<button class="ctrl-del-user" style="width: 100px; height: 25px; margin-top: 5px;">删除</button>
</div>
</div>
<?php
}
?>系统的入口: index.php
<?php 
/**
 * 程序入口
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel='stylesheet' type='text/css' href='./styles/ui.all.css' />
<link rel='stylesheet' type='text/css' href='./styles/fullcalendar.css' />
<link rel='stylesheet' type='text/css' href='./styles/eat.css' />
<script type='text/javascript' src='./scripts/jquery.js'></script>
<script type='text/javascript' src='./scripts/jquery-ui-1.7.2.custom.js'></script>
<script type='text/javascript' src='./scripts/fullcalendar.js'></script>
<script type='text/javascript' src='./scripts/eat.js'></script>
</head>
<body>
<button id="maintain">加人</button>
<div id='calendar' class="wrapper"></div>
</body>
</html>系统涉及的javascript: eat.js
$(document).ready(function() {
/**
 * 计算一月有多少天
 */
function daysInMonth(month,year) {
var dd = new Date(year, month, 0);
return dd.getDate();

/**
 * 预置日历初始化使用日期, 当天
 */
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();

/**
 * 初始化日历中每天里面的上下午日程
 */
var day_nums = daysInMonth(m, y);
var events = new Array();
for(var i = 1; i < day_nums; i ++) {
events.push({
title: '上午吃啥', 
start: new Date(y, m, i, 1), 
end: new Date(y, m, i, 11)
});
events.push({
title: '下午吃啥', 
start: new Date(y, m, i, 14), 
end: new Date(y, m, i, 23)
});
}

/**
 * 初始化日历
 */
$('#calendar').fullCalendar({
year: y, 
month: m, 
day: d, 
defaultView: 'month', 
events: events, 
header: {left: '', center: 'title', right: ''}, 
aspectRatio: 1.6, 
weekMode: 'variable', 
eventClick: function(calEvent, jsEvent, view) {
/**
 * 日程被点击后, 加载该时段的订餐视图
 */
$('<div>').load('./viewItems.php?t=' + (calEvent.start / 1000), function() {
var self= this;
/**
 * 订餐的提交
 */
$('.ctrl-submit', this).bind('click', function(event) {
var record = $(this).parents('tr.ctrl-record').get(0);
var userId = $(record).attr('userId');
var food = $('.ctrl-food-input', record).val();
$(self).dialog('close');
$.ajax({
type: 'POST', 
url: './submitItem.php', 
data:'userId=' + userId + '&food=' + food + '&t=' + (calEvent.start / 1000), 
async: false,  
success: function(res) {
$('<div>').text('嘿嘿嘿, 吃好喝好啊.').dialog({
resizable: false, 
modal: true, 
title: '订了, 该干啥干啥吧.', 
width: 600, 
close: function() {
$(this).dialog('destroy').remove();
}, 
buttons: {
'就是关的时候方便点1': function() {
$(this).dialog('close');
}, 
'就是关的时候方便点2': function() {
$(this).dialog('close');
}, 
'就是关的时候方便点3': function() {
$(this).dialog('close');
}
}
});
}
});
});
/**
 * 把加载到的订餐视图预置为jqueryUI.dialog
 */
var t = new Date(calEvent.start);
$(this).css('margin', '0 auto').dialog({
resizable: false, 
modal: true, 
title: '[' + t.getFullYear() + '年' + (t.getMonth() + 1) + '月' + t.getDay() + '日' + (t.getHours() > 13 ? '下午' : '上午') + ']----你想吃啥啊?', 
width: 1000, 
close: function() {
$(this).dialog('destroy').remove();
}, 
buttons: {
'就是关的时候方便点1': function() {
$(this).dialog('close');
}, 
'就是关的时候方便点2': function() {
$(this).dialog('close');
}, 
'就是关的时候方便点3': function() {
$(this).dialog('close');
}
}
});
});
}

});
/**
 * 修改当天的DOM, 加明显标记
 */
$('.fc-today').append('<div style="margin-top: 40px; color: #888933; font-size: 20px; font-weight: bold;">这里是今天</div>');
/**
 * 加人按钮, 用来加载用户管理界面
 */
$('#maintain').bind('click', function(event) {
$('<div>').load('./viewUsers.php', function() {
$(this).dialog({
resizable: false, 
modal: true, 
title: '嘿嘿, 吃着喝着啊', 
width: 1128,
height: 450, 
close: function() {
$(this).dialog('destroy').remove();
}, 
buttons: {
'就是关的时候方便点1': function() {
$(this).dialog('close');
}, 
'就是关的时候方便点2': function() {
$(this).dialog('close');
}, 
'就是关的时候方便点3': function() {
$(this).dialog('close');
}, 
'就是关的时候方便点4': function() {
$(this).dialog('close');
}
}
});
bindMaitainArea(this);
});
});
/**
 * 用户管理界面加载完毕之后, 对其上的按钮绑定事件
 */
var bindMaitainArea = (function(context) {
/**
 * 新增用户的事件
 */
$('#new_user', context).bind('click', function(event) {
var self = this;
$.ajax({
type: 'POST', 
url: './addUser.php', 
data:'name=' + $('#new_user_input').val(), 
timeout:8000,
async: false,  
success: function(res) {
$(self).parents('.ui-dialog-content').load('./viewUsers.php', function() {
bindMaitainArea();
});
}
});
});
/**
 * 删除用户的事件
 */
$('.ctrl-del-user', context).bind('click', function(event) {
var self = this;
$.ajax({
type: 'POST', 
url: './delUser.php', 
data:'id=' + $(self).parents('.ctrl-record').attr('userId'), 
timeout:8000,
async: false,  
success: function(res) {
$(self).parents('.ui-dialog-content').load('./viewUsers.php', function() {
bindMaitainArea();
});
}
});
});
});
});
系统涉及的自定义样式: eat.css@CHARSET "UTF-8";
body{font-size: 75%;}
.wrapper{width: 1024px; margin: 0 auto;}.food-input{width: 300px; border: 1px solid #E0E0E0;}table{border-left: 1px solid #D0D0D0; border-top: 1px solid #D0D0D0;}
th, td{border-right: 1px solid #D0D0D0; border-bottom: 1px solid #D0D0D0;}

解决方案 »

  1.   


    呵呵, 没演示站点, 代码拷下去, 数据库链接改了, 把调整时间差的地方改了, 放apache下就应该可以演示了
      

  2.   

    女孩子适合做程序员吗,PHP最好的开发工具
      

  3.   


    你太牛了, 哥们儿, 这都能看出来.....
    我做了2年java, php才2个月....不过我觉得JAVA里SSH三大开源框架中提到的思想是很好的.....
    PHP中的Thinkphp, cakephp原理上不都和Struts整合Hibernate类似吗....
    只是php中没有服务器生命周期(ApplicationScope), 所以, 就没有类似spring的东西
      

  4.   

    用了大量的类啊 典型的java
      

  5.   


    PHP中的类会在每次解释的时候重新定义吗?
      

  6.   

    学学更健康管他java还是PHP都学了
      

  7.   

    感觉很不习惯啊,都是类,类在用的时候还有实例化。User 这个对象里面的 $id $name 为什么 私有啊?----------------------------
    还有这样的:    public function getId() {
            return $this->id;
        }
    直接 $User->id 不就得了吗?浪费代码啊~~~~~~
    反正不习惯,不喜欢。随便你怎么反对
    PHP的说实话,用类 不方便
      

  8.   

    先顶后看  哥们太牛了!@#¥%……&*
      

  9.   

    PHP中的类会在每次解释的时候重新定义吗?
      

  10.   

    希望楼主能把项目打个包,给个下载的链接
    一直想学php,可以研究一下
      

  11.   

    PHP牛人,模拜了!4个多小时就搞定了。我学了2年多了。说真的没有一天一夜,我是完成不了的,天资过人,佩服!
      

  12.   

    为 java-like 而 java-like。代码臃肿。
      

  13.   


    呵呵....不是为x而x, 是原本就是java程序员
      

  14.   

    能不能 把jquery的js也发一下呢
      

  15.   

    4.5个小时?真棒,生平第一次在这个论坛发贴,纪念。
    顺便问下准备跳槽不?
    工作介绍
    PHP
    MySQL
    can quickly adapt to work with two [2] different CMF/CMS systems (MODx and a large scale eCommerce CMS)As the right candidate, you can expect;
    positive work environment
    attractive and motivating renumeration packages
    tremendous growth potential
      

  16.   

    过我觉得JAVA里SSH三大开源框架中提到的思想是很好的.....
    PHP中的Thinkphp, cakephp原理上不都和Struts整合Hibernate类似吗....
    只是php中没有服务器生命周期(ApplicationScope), 所以, 就没有类似spring的东西