我正在为跆拳道学校创建一个时间表,我希望管理员能够删减他们的表格。
这是我想要的样子:
这是我现在的代码:
<?php if (!$session->is_logged_in()) { redirect_to("login.php"); } ?>
$schedules = Schedule::find_all();
?>
Schedule
if(isset($_POST['delete'])){
$schedule = Schedule::find_by_id($_GET['id']);
if($schedule && $schedule->delete()) {
$session->message("The line was deleted.");
redirect_to('schedule.php');
}else{
$session->message("The line could not be deleted.");
redirect_to('schedule.php');
}
}
?>
if(isset($_POST['submit'])){
$schedule = new Schedule();
$schedule->belt = $_POST['belt'];
$schedule->age = $_POST['age'];
$schedule->monday = $_POST['monday'];
$schedule->tuesday = $_POST['tuesday'];
$schedule->wednesday = $_POST['wednesday'];
$schedule->thursday = $_POST['thursday'];
$schedule->friday = $_POST['friday'];
$schedule->saturday = $_POST['saturday'];
if($schedule->save()) {
$session->message("line added successfully.");
redirect_to('schedule.php');
} else {
$message = join("<
", $schedule->errors);
}
}
?>
if(isset($_POST['update'])){
$schedule = Schedule::find_by_id($_POST['id']);
$schedule->belt = $_POST['belt'];
$schedule->age = $_POST['age'];
$schedule->monday = $_POST['monday'];
$schedule->tuesday = $_POST['tuesday'];
$schedule->wednesday = $_POST['wednesday'];
$schedule->thursday = $_POST['thursday'];
$schedule->friday = $_POST['friday'];
$schedule->saturday = $_POST['saturday'];
if($schedule->save()) {
$session->message("line updated successfully.");
redirect_to('schedule.php');
} else {
$message = join("<
", $schedule->errors);
}
}
?>
Belt | Age | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | |
---|---|---|---|---|---|---|---|---|
<?php include_layout_template('admin_footer.php'); ?>我想做一些额外的增强功能,但我无法弄清楚这种形式。直到我添加了更新的功能之前,它工作得很好。现在,当我将一些新数据添加到其中一行时,然后单击更新 - 它不会给我一个会话消息,也不会更新视图中的字段(但我认为它在数据库中)。
任何意见,将不胜感激。我想我可以用一些AJAX来解决这个问题 - 但我一段时间没有碰到它,坦白地说,不记得如何...