コード例 #1
0
ファイル: DishController.php プロジェクト: rodericj/TopDish
 public function addAction()
 {
     $restID = $this->_getParam('rest_id', 0);
     $fooditems = new Model_DbTable_FoodItems();
     $categories = $fooditems->fetchAll();
     $cat_list = array();
     foreach ($categories as $cat) {
         $cat_list[$cat['id']] = $cat['name'];
     }
     $restaurants = new Model_DbTable_Restaurants();
     $itemsRowset = $restaurants->find($restID);
     $thisRest = $itemsRowset->current();
     $restName = $thisRest['name'];
     $this->view->title = "Add new dish at " . $restName;
     $this->view->headTitle($this->view->title, 'PREPEND');
     $options = array('restID' => $restID, 'fooditems' => $cat_list);
     $form = new Form_Dish($options);
     $form->submit->setLabel('Add');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $name = $form->getValue('name');
             $restaurantID = $form->getValue('restaurantID');
             $fooditemID = $form->getValue('fooditemID');
             $dishes = new Model_DbTable_Dishes();
             $dishes->addDish($name, $restaurantID, $fooditemID);
             $id = $this->_getParam('id', 0);
             if ($id > 0) {
                 $this->_redirect('/fooditem/showdishes/id/' . $id);
             } else {
                 $this->_redirect('/dish');
             }
         } else {
             $form->populate($formData);
         }
     }
 }