更具体地说,我有一个创建和编辑事件的Web应用程序。在我的db表上有一个新截断之后,当我创建一个事件时,它以id = 1开始(虽然如果我记得它应该以0开头),当我编辑特定事件(在这种情况下,id = 1)时当我检查表时,phpmyadmin将id = 1的事件更改为id = 0,当我尝试添加新事件时,它跳转到id = 2。
数据库类:
class Application_Model_DbTable_Eventsdb extends Zend_Db_Table_Abstract {
protected $_name = 'events';
public function CreateEvent($category, $title, $subtitle, $video, $date, $ages, $resume, $description, $image1, $image2, $image3, $image4, $image5) {
$data = array(
"id" => NULL,
"category" => $category,
"title" => $title,
"subtitle" => $subtitle,
"video" => $video,
"date" => $date,
"ages" => $ages,
"resume" => $resume,
"description" => $description,
"image1" => $image1,
"image2" => $image2,
"image3" => $image3,
"image4" => $image4,
"image5" => $image5
);
$this->insert($data);
return TRUE;
}
public function UpdateEvent($eventID, $category, $title, $subtitle, $video, $date, $ages, $resume, $description, $image1, $image2, $image3, $image4, $image5) {
$bind = array(
"id" => NULL,
"category" => $category,
"title" => $title,
"subtitle" => $subtitle,
"video" => $video,
"date" => $date,
"ages" => $ages,
"resume" => $resume,
"description" => $description,
"image1" => $image1,
"image2" => $image2,
"image3" => $image3,
"image4" => $image4,
"image5" => $image5
);
$where = "`id` = $eventID";
$this->_db->update($this->_name, $bind, $where);
}
管理员控制器:
class AdminController extends Zend_Controller_Action {
public function createEventAction() {
$eventdb = new Application_Model_DbTable_Eventsdb();
$form = new Application_Form_CreateEvent();
$this->view->event_form = $form;
if ($this->getRequest()->isPost()) {
if ($form->isValid($_POST)) {
$formdata = $form->getValues();
$confirmation = $eventdb->CreateEvent($formdata['category'], $formdata['title'], $formdata['subtitle'], $formdata['video'], $formdata['date'], $formdata['ages'], $formdata['resume'], $formdata['description'], $formdata['image1'], $formdata['image2'], $formdata['image3'], $formdata['image4'], $formdata['image5']);
if ($confirmation) {
$this->view->confirmation = "Evenimentul a fost introdus cu success.";
}
}
}
}
public function editEventAction() {
$eventdb = new Application_Model_DbTable_Eventsdb();
$form = new Application_Form_EditEvent();
$this->view->tabere = $eventdb->getEventsbyCategory('Tabara');
$this->view->ateliere = $eventdb->getEventsbyCategory('Atelier');
$this->view->workshopuri = $eventdb->getEventsbyCategory('Workshop');
$this->view->petreceri = $eventdb->getEventsbyCategory('Petrecere');
$this->view->alte = $eventdb->getEventsbyCategory('Alt');
if (isset($_GET['eventID'])) {
$eventID = $_GET['eventID'];
$event_data = $eventdb->getEventsbyId($eventID);
$this->view->event_data = $event_data;
$this->view->form = $form;
}
if ($this->getRequest()->isPost()) {
if ($form->isValid($_POST)) {
$renew_data = $form->getValues();
$eventdb->UpdateEvent($eventID, $renew_data['category'], $renew_data['title'], $renew_data['subtitle'], $renew_data['video'], $renew_data['date'], $renew_data['ages'], $renew_data['resume'], $renew_data['description'], $renew_data['image1'], $renew_data['image2'], $renew_data['image3'], $renew_data['image4'], $renew_data['image5']);
$this->_redirect('EditeazaEveniment');
}
}
}
}
答案 0 :(得分:1)
在您的更新功能中,您已告知MySQL将id设置为NULL。它不能那样做,所以它试图做下一个最好的事情,在这种情况下将该值转换为0.因为你不想改变id值,要么删除那个键&来自$bind
数组的值或将正确的eventID值放在那里。