[eluser]shinokada[/eluser]
I have the following control which works with function checkOrphans(). If this checkOrphans returns redirect to reassign, otherwise delete the category.
In reassign() function, after reassignProducts () function, it supposed to delete with deleteCategroy() function.
This works if there is no orphans and delete the category.
If there are orphans, it redirects to reassign, but after this it does not delete the category, even I am using the same deleteCategory function.
Can anyone spot me out why it does not work?
Thanks in advance.
Code:
function delete($id){
...
...
$orphans = $this->MCats->checkOrphans($id);
if (count($orphans)){
$this->session->set_userdata('orphans',$orphans);
redirect('admin/categories/reassign/'.$id,'refresh');
}else{
$this->MCats->deleteCategory($id);
$this->session->set_flashdata('message','Category deleted');
redirect('admin/categories/index','refresh');
}
}
function reassign($id=0){
if ($_POST){
$this->MProducts->reassignProducts();
$this->MCats->deleteCategory($id); // this is not working at the moment.
$this->session->set_flashdata('message','Category deleted and products reassigned');
redirect('admin/categories/index','refresh');
}else{
//$id = $this->uri->segment(4);
$data['category'] = $this->MCats->getCategory($id);
$data['title'] = "Reassign Products";
$data['main'] = 'admin_cat_reassign';
$data['categories'] = $this->MCats->getCategoriesDropDown();
$this->load->vars($data);
$this->load->view('dashboard');
}
}
And in model
Code:
function checkOrphans($id){
$data = array();
$this->db->select('id,name');
$this->db->where('category_id',id_clean($id));
$Q = $this->db->get('omc_product');
if ($Q->num_rows() > 0){
foreach ($Q->result_array() as $row){
$data[$row['id']] = $row['name'];
}
}
$Q->free_result();
return $data;
}
function deleteCategory($id){
// $data = array('status' => 'inactive');
$this->db->where('id', id_clean($id));
$this->db->delete('omc_category');
}
In the reassign view
Code:
echo form_open('admin/categories/reassign');
unset($categories[$category['id']]);
echo form_dropdown('categories',$categories);
echo form_submit('submit','reassign');
echo form_close();