Controller
function create(){
// we are using TinyMCE in this page, so load it
$this->bep_assets->load_asset_group('TINYMCE');
if ($this->input->post('name')){
// fields are filled up so do the followings
$this->MProducts->insertProduct();
redirect('products/admin/index','refresh');
}else{
// this must be the first time, so set variables
$data['title'] = "Create Product";
$this->load->view('image_upload',$data);
}
}
Model
function insertProduct(){
$data = array(
'name' => db_clean($_POST['name']),
'shortdesc' => db_clean($_POST['shortdesc']),
'longdesc' => db_clean($_POST['longdesc'],5000),
...
...
'image1' => db_clean($_POST['image1']),
'image2' => db_clean($_POST['image2'])
);
$this->db->insert('omc_product', $data);
$new_product_id = $this->db->insert_id();
}
View
echo form_open_multipart('products/admin/create')."\n";
echo "<p><label for='parent'>Category</label><br/>\n";
echo form_dropdown('category_id',$categories) ."</p>\n";
echo "<p><label for='pname'>Name</label><br/>";
$data = array('name'=>'name','id'=>'pname','size'=>25);
echo form_input($data) ."</p>\n";
...
echo "<p><label for='image1'>Select Image</label><br/>";
$data = array('name'=>'image1','id'=>'image1','size'=>80);
echo form_textarea($data) ."</p>\n";
echo "<p><label for='image2'>Select another image</label><br/>";
$data = array('name'=>'image2','id'=>'image2','size'=>80);
echo form_textarea($data) ."</p>\n";
...
...
echo form_submit('submit','create product');
echo form_close();