嘿,夥計們,我在漫長的夜晚後超級卡住了。菜單hasMany Widget,Widget hasMany WidgetItem(當然還有WidgetItem belongsTo Widget,Widget belongsTo Menu)。我創建了一個應用程序,您可以動態創建食物菜單,並建立如下關係:爲多個模型保存多個記錄cakephp
菜單首先被創建,然後用戶被重定向到addSectionsToMenu,在那裏我分別設置了多個小工具(標題輸入)和多個項目(菜單項)。
我的小部件保存並附加到菜單上,但我的WidgetItems不保存。我確信我的模型設置得很好,我花了2個小時對我的$ data結構進行了整理。我只是覺得我需要在這裏弄清楚一些事情。
請幫忙!
感謝,
〜哈雷
function addSectionsToMenu($menu_id = null){
$this->layout = 'admin';
$this->set('menu_id', $menu_id);
$this->set('menu', $this->Widget->Menu->findById($menu_id));
if (!$menu_id && empty($this->data)) { $this->Session->setFlash(__('Pick a menu to add to please :)', true)); }
$saveSuccess = false;
if(!empty($this->data['Widget'])) {
$widget_count = 0;
foreach($this->data['Widget'] as $widgetKey => $widget) :
if($this->Widget->saveAll($widget)) : $saveSuccess = true; endif;
$widget_count++;
endforeach;
if ($saveSuccess) {
$this->Session->setFlash(__($widget_count.' sections have been added to the Menu', true));
$this->redirect(array('controller' => 'menus', 'action' => 'index'));
} else {
$this->Session->setFlash(__('The Menu and Sections could not be saved. Please, try again.', true));
}
}
}
$ this-> Widget-> validationErrors的值是多少?將config/core.php中的DEBUG常量設置爲3,以查看SQL的完整調試和當前對象的轉儲。這兩件事中的一件應該可以幫助你找到問題所在。 – 2011-05-19 02:14:42