Example #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();
 }
		 
		  <div id="tab_flavors" >
			  <div class="headline">Flavors</div>
			  <table>
			  <colgroup>
					<col width="150" />
					<col  />
			  </colgroup>
			  <tr>
			  		<td><label for="metaTitle">Name</label></td>
					<td><label for="metaTitle">Description</label></td>
			  </tr>
			<?php 
foreach ($productflavors as $productflavorid) {
    $fid = $productflavorid->flavorID;
    $flavorsmodel = new Flavor_Model();
    $flavor = $flavorsmodel->getFlavorByID($fid);
    //foreach($flavors as $flavor){
    echo '<tr>';
    echo '<td><label for="flavorName">' . $flavor->name . '</label></td>';
    echo '<td><label for="flavorDesc">' . $flavor->description . '</label></td>';
    echo '</tr>';
    //}
}
?>
			
			
			  
			  </table>
		 </div>   <!-- div id="tab_costs" -->
		 
{
	// Automatically calculates the editor base path based on the _samples directory.
	// This is usefull only for these samples. A real application should use something like this:
	// oFCKeditor.BasePath = '/fckeditor/' ;	// '/fckeditor/' is the default value.
	var sBasePath = '<?php 
echo url::base();
?>
/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