Пример #1
0
 public function editTourAction()
 {
     $form = $this->view->form = new Yntour_Form_Tour_Create();
     $model = new Yntour_Model_DbTable_Tours();
     $id = $this->_getParam('tour_id', 0);
     $item = $model->find($id)->current();
     $request = $this->getRequest();
     if ($request->isGet()) {
         if (is_object($item)) {
             $form->populate($item->toArray());
         } else {
             $uri = parse_url($request->getServer('HTTP_REFERER'));
             $path = trim($uri['path']);
             $baseURL = $request->getBaseUrl();
             $path = str_replace($baseURL, '', $path);
             $bodyid = $this->_getParam('body', 'global_page_user-index-home');
             $form->populate(array('path' => $path, 'bodyid' => $bodyid));
         }
         return;
     }
     if ($request->isPost() && $form->isValid($request->getPost())) {
         $data = $form->getValues();
         if (!is_object($item)) {
             $item = $model->fetchNew();
             $item->creation_date = date('Y-m-d H:i:s');
             $item->setPath($form->getValue('path'));
             $item->hash = md5(mt_rand(0, 999999) . mt_rand(0, 999999) . mt_rand(0, 99999), false);
         }
         $item->setFromArray($data);
         if (!$item->save()) {
             throw Exception("Invalid data");
         }
         $this->_forward('success', 'utility', 'core', array('smoothboxClose' => 10, 'parentRefresh' => 10, 'messages' => array('Successful.')));
     }
 }
Пример #2
0
 public function createAction()
 {
     $form = $this->view->form = new Yntour_Form_Admin_Tour_Create();
     $request = $this->getRequest();
     if ($request->isGet()) {
         return;
     }
     if ($request->isPost() && $form->isValid($request->getPost())) {
         $data = $form->getValues();
         $model = new Yntour_Model_DbTable_Tours();
         $item = $model->fetchNew();
         $item->setFromArray($data);
         $item->creation_date = date('Y-m-d H:i:s');
         if ($item->save()) {
             $this->_redirect('admin/yntour/manage');
         }
     }
 }