2014-09-18 44 views
1

我有一個事件觀察員。 Oberver代碼:Magento不保存表中的所有數據

public function saveQuoteAfter($evt) { 
     $quote = $evt->getQuote(); 
     $quoteIddd = $quote->getId(); 
     $email = $quote->getPEmail(); 
     $phone = $quote->getPPhone(); 
     $p = $quote->getPP(); 
     $fields = array('quote_id' => $quoteIddd, 'email' => $email, 'phone' => $phone, 'p' => $p); 
     $model = Mage::getModel('my_module/quote')->setData($fields); 
     $model->save(); 
    } 

法師:: getModel( 'my_module /報價') - 這是保存數據表自定義模型。 所有變量都存在,可以保存在表格的前3列中。不能將任何數據保存到任何其他列。

install script: 
$installer = $this; 
$installer->startSetup(); 
$installer->run(" 
CREATE TABLE IF NOT EXISTS {$this->getTable('module_quote')} (
    `id` int(11) unsigned NOT NULL auto_increment, 
    `quote_id` int(11) unsigned NOT NULL, 
    `email` text NOT NULL, 
    `phone` text NOT NULL, 
    `p` text NOT NULL, 
    PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
$installer->endSetup(); 

所以我不能保存數據到'p'欄。任何想法爲什麼magento不會將數據保存到這些列?

回答

-1

ciemin而不是使用of setData() use addData()

由於使用setData只能保存一個值 actully這個功能看起來像

public function addData(array $arr) 
    { 
     foreach($arr as $index=>$value) { 
      $this->setData($index, $value); 
     } 
     return $this; 
    } 

由於使用addData功能,您可以使用索引,但使用setData只保存索引的前一個值數組值:使用setData(「字段名」 ,$ val)

+0

它的工作,謝謝。 – ciemin 2014-09-19 07:29:32

+0

實際上,setData雖然可以設置單個對象屬性,但主要用於數據數組(您可以檢查Varien_Object類中該方法的外觀)。 – 2014-09-19 07:31:22

+0

請接受我的回答 – 2014-09-19 07:34:24

相關問題