function save($object = '', $related_field = '') { if (!$this->exists()) { $o = new producthome(); $o->where("productcat_id", $this->productcat_id); $o->select_max('position'); $o->get(); if (count($o->all) != 0) { $max = $o->position + 1; $this->position = $max; } else { $this->postion = 1; } $o->clear(); $o = new producthome(); $o->where('productcat_id', $this->productcat_id); $o->where('product_id', $this->product_id); $o->get(); if ($o->exists()) { return true; } } return parent::save($object, $related_field); }
function updateProductHomePosition($cat_id) { $allPost = array_keys($_POST); foreach ($allPost as $row) { if (substr($row, 0, 19) == "productHomePosition") { $productHomeId = explode("_", $row); $productHome = new producthome($productHomeId[1]); $productHome->position = $this->input->post($row); $productHome->save(); $productHome->clear(); } } redirect("admin/productcats/edit/" . $cat_id); }