2014-01-16 48 views
0

我試圖將一些數據保存到我的表gal_photographers。雖然我的表結構是:var_dump()cakephp中的save()函數不顯示所有字段

CREATE TABLE IF NOT EXISTS `gal_photographers` (
    `id` int(4) NOT NULL AUTO_INCREMENT, 
    `gal_provider_id` int(4) NOT NULL, 
    `starting_month` varchar(2) NOT NULL DEFAULT '01', 
    `starting_year` varchar(4) NOT NULL DEFAULT '2010', 
    `starting_package_wedding` int(7) NOT NULL, 
    `starting_package_prewedding` int(7) NOT NULL, 
    `starting_package_studio` int(7) NOT NULL, 
    `willing_to_travel` tinyint(1) NOT NULL DEFAULT '0', 
    `candid_photography` tinyint(1) NOT NULL DEFAULT '0', 
    `traditional_photography` tinyint(1) NOT NULL DEFAULT '0', 
    `pre-wedding` tinyint(1) NOT NULL DEFAULT '0', 
    `portraiture` tinyint(1) NOT NULL DEFAULT '0', 
    `portfolios` tinyint(1) NOT NULL DEFAULT '0', 
    `location_shoots` tinyint(1) NOT NULL DEFAULT '0', 
    `videography` tinyint(1) NOT NULL DEFAULT '0', 
    `awards1` varchar(100) NOT NULL, 
    `awards2` varchar(100) NOT NULL, 
    `awards3` varchar(100) NOT NULL, 
    `video_title1` varchar(150) NOT NULL, 
    `video_link1` varchar(150) NOT NULL, 
    `video_title2` varchar(150) NOT NULL, 
    `video_link2` varchar(150) NOT NULL, 
    `video_title3` varchar(150) NOT NULL, 
    `video_link3` varchar(150) NOT NULL, 
    PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=455 ; 

,我試圖以保存:

$sv = $this->GalPhotographer->save(); 
var_dump($sv); 
if($sv) { 
    echo 'SUCCESS'; 
}else{ echo 'NO SUCCESS !'; 
} 

但上面save()不是插入的所有數據。此外,該var_dump($sv)顯示:

array (size=1) 
    'GalPhotographer' => 
    array (size=10) 
     'starting_month' => string '01' (length=2) 
     'starting_year' => string '2010' (length=4) 
     'willing_to_travel' => string '0' (length=1) 
     'candid_photography' => string '0' (length=1) 
     'traditional_photography' => string '0' (length=1) 
     'pre-wedding' => string '0' (length=1) 
     'portraiture' => string '0' (length=1) 
     'portfolios' => string '0' (length=1) 
     'location_shoots' => string '0' (length=1) 
     'videography' => string '0' (length=1) 

當然,雖然我所有的數據都沒有插入我得到一個消息SUCCESS

+1

這些值是什麼? – Anubhav

+1

模型如何?你有場驗證? – cornelb

回答

0

我有點不清楚你試圖從哪裏獲取數據。我猜它應該來自帶有窗體的視圖,窗體是否正確提交?

save()實際上現在保存的是您在sql命令中定義的默認值。

Cakes Form Helper全部創建一個表格,並將其提交給相應的操作。這些行爲應該看起來像下面這樣...

public function add($gal_provider_id = null) { 
    if (!$gal_provider_id) { 
     throw new NotFoundException(__('Invalid Gal Provider')); 
    } 
    $this->set('provider', $gal_provider_id); 
    if ($this->request->is('post') || $this->request->is('put')) { 
     $this->GalPhotographer->create(); 
     if ($this->GalPhotographer->save($this->request->data)) { 
      $this->Session->setFlash(__('Success!')); 
     } else { 
      $this->Session->setFlash(__('No success!')); 
     } 
    } 
} 

public function edit($id = null) { 
    if (!$id) { 
     throw new NotFoundException(__('Invalid GalPhotographer')); 
    } 
    $phtgrpher = $this->GalPhotographer->findById($id); 
    if (!$phtgrpher) { 
     throw new NotFoundException(__('Invalid GalPhotographer')); 
    } 

    if ($this->request->is('post') || $this->request->is('put')) { 
     $this->GalPhotographer->create(); 
     if ($this->GalPhotographer->save($this->request->data)) { 
      $this->Session->setFlash(__('Success!')); 
     } else { 
      $this->Session->setFlash(__('No success!')); 
     } 
    } 

    if (!$this->request->data) { 
     $this->request->data = $phtgrpher; 
    } 
}