我有一個Zend_Form的Zend的表單字段映射到數據庫列
$form = new My_Form();
$uploadedData = $form->getValues();
Zend_Debug::dump($uploadedData, $form->name,true)
,當我轉儲形式值我得到一個字符串數組
array(11) {
["event"] => string(2) "26"
["firstname"] => string(3) "sdf"
["surname"] => string(0) ""
["gender"] => string(1) "M"
["company"] => NULL
["dateOfBirth"] => string(10) "11-11-1977"
["address"] => string(6) "dfasdf"
["address2"] => string(4) "adfs"
["address3"] => string(4) "adfs"
["email"] => string(7) "[email protected]"
["mobile"] => string(0) ""
}
形式具有相同數量的字段我數據庫表,數據庫表DEF是
DROP TABLE IF EXISTS `registration`;
CREATE TABLE IF NOT EXISTS `registration` (
`id` int(11) NOT NULL auto_increment,
`event` int(11) NOT NULL,
`firstname` varchar(50) NOT NULL,
`surname` varchar(50) NOT NULL,
`gender` varchar(5) NOT NULL,
`dateofbirth` date NOT NULL,
`address` varchar(50),
`address2` varchar(50),
`address3` varchar(50),
`email` varchar(50) NOT NULL,
`mobile` varchar(50),
`company` int(11),
`sector` int(11),
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
我得到的時刻映射錯誤,因爲DB事件列可以別帶走一個字符串, 同樣用‘出生日期’一欄
if($form->isValid($formData))
{
$logger->info("valid form");
$table = new Model_DbTable_Registration();
... // apply some custom mapping??
$table->insert($uploadedData);
...
}
我不想手動創建一個新的數組,每個表單字段映射到正確類型的名字 - 它 看起來很痛苦。在Zend中有沒有更智能的方法來做這種映射?
你用什麼樣的輸入來設置「事件」?如果數據是數字的,那麼當您追蹤數組時,它應該是數字。 – typeoneerror 2009-10-26 14:32:04