Beispiel #1
0
 public function add()
 {
     $argumentarray = Router::$arguments;
     //$id = $argumentarray[0];
     //$id = $flavors->getNextID();
     if (isset($_POST['save'])) {
         $post = new Validation(array_merge($_POST, $_FILES));
         $post->pre_filter('trim', 'flavorName', 'flavorDescription');
         $post->add_rules('flavorName', 'required');
         $post->add_rules('flavorDescription', 'required');
         if (!$post->validate()) {
             $errors = $post->errors('form_errors');
             foreach ($errors as $error) {
                 echo '<p class="error">' . $error . '</p>';
             }
         } else {
             //$id = $argumentarray[0];
             $flavors = new Flavor_Model();
             $flavor = ORM::factory('flavor');
             $flavor->name = $post->flavorName;
             $flavor->description = $post->flavorDescription;
             try {
                 $flavor->save();
                 $flavors = new Flavor_Model();
                 $id = $flavors->getNextID();
                 url::redirect('/flavors/edit/' . $flavor->id);
             } catch (Exception $ex) {
                 echo 'There was an error adding this flavor: ' . $ex->getMessage();
                 //url::redirect('/flavors/');
             }
         }
     }
     $this->_renderView();
 }
?>
/media/js/fckeditor/';

	
}
</script>

<?php 
$argumentarray = Router::$arguments;
$flavors = new Flavor_Model();
if (isset($argumentarray[0])) {
    $id = $argumentarray[0];
    $flavor = $flavors->getFlavorByID($id);
} else {
    //
    $id = $flavors->getNextID();
    $flavor = ORM::factory('flavor');
}
$i = 0;
$j = 0;
?>
		


<form action="<?php 
if (isset($id)) {
    echo url::base() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/' . $id;
} else {
    echo url::base() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/';
}
?>