Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. function addSectionsToMenu($menu_id = null){
  2.      $this->layout = 'admin';
  3.      $this->set('menu_id', $menu_id);
  4.      $this->set('menu', $this->Widget->Menu->findById($menu_id));
  5.      $this->set('existing_widgets', $this->Widget->findAllByMenuId($menu_id));
  6.      if (!$menu_id && empty($this->data)) {
  7.         $this->Session->setFlash(__('Pick a menu to add to please :)', true));
  8.      }
  9.      if(!empty($data['Widget'])) {
  10.         $saveSuccess = true;
  11.         foreach($data['Widget'] as $widgetData) :
  12.             $this->Widget->create();
  13.             if($this->Widget->saveAll($widgetData)) : $saveSuccess = true; endif;
  14.         endforeach;
  15.        
  16.         if ($saveSuccess) {
  17.             $this->Session->setFlash(__('The Section(s) has been saved', true));
  18.             $this->redirect(array('action' => 'index'));
  19.         } else {
  20.             $this->Session->setFlash(__('The Sections could not be saved. Please, try again.', true));
  21.         }
  22.      }
  23.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement