我正在尝试在我的表中插入数据,但总是得到此错误
致命错误:调用未定义的方法UltimoValue_Warranty_Model_Mysql4_Warranty_Collection :: setData()in /var/www/magento.dev/app/code/community/UltimoValue/Warranty/controllers/IndexController.php 第17行
这是IndexController中的保存代码
public function saveAction()
{
$warrantiesCollection = Mage::getModel('warranty/warranty')->getCollection();
$post = $this->getRequest()->getPost();
if(isset($post['order_number']) && isset($post['save'])) {
try {
$warrantiesCollection->setData('id', null);
$warrantiesCollection->setData('first_name', $post['first_name']);
$warrantiesCollection->setData('last_name', $post['last_name']);
$warrantiesCollection->setData('order_number', $post['order_number']);
$warrantiesCollection->setData('tablet_serial_number', $post['tablet_serial_number']);
$warrantiesCollection->setData('date_purchased', $post['date_purchased']);
$warrantiesCollection->save();
} catch(Exception $e) {
echo $e->getMessage(), "\n";
}
header("Location: " . $_SERVER['HTTP_ORIGIN'] . "/index.php/warranty/index/thankyou/");
exit();
}
}
当我使用getData时 - 一切都很好......
我做错了什么?
答案 0 :(得分:2)
代替
$warrantiesCollection = Mage::getModel('warranty/warranty')->getCollection();
我必须写
$warrantiesCollection = Mage::getModel('warranty/warranty');
感谢所有