Ejemplo n.º 1
0
 public function editAction()
 {
     $form = new \DF\Form($this->current_module_config->forms->url);
     if ($this->hasParam('id')) {
         $record = ShortUrl::getRepository()->find($this->getParam('id'));
         $form->setDefaults($record->toArray());
     }
     if (!empty($_POST) && $form->isValid($_POST)) {
         $data = $form->getValues();
         if (!$record instanceof ShortUrl) {
             $record = new ShortUrl();
         }
         $record->fromArray($data);
         if (!$record->checkUrl()) {
             throw new \DF\Exception\DisplayOnly('This URL is already taken! Please go back and try another.');
         }
         $record->save();
         $this->alert('Record updated.', 'green');
         $this->redirectFromHere(array('action' => 'index', 'id' => NULL));
         return;
     }
     $this->renderForm($form, 'edit', $this->hasParam('id') ? 'Edit Short URL' : 'Add Short URL');
 }