<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Dashboard extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->model('newcategory');
}
public function category()
{
$data['category'] = $this->newcategory->showcategorydetails();
$this->load->view('template/header',$data);
$this->load->view('template/sidebar');
$this->load->view('category', array('error' => ' ' ));
$this->load->view('template/footer');
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Newcategory extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function lastregistration_id()
{
return $this->db->insert_id();
}
public function newcategory_partone()
{
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('date');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
redirect('dashboard/category', 'refresh');
}
else
{
$data = array('upload_data' => $this->upload->data());
foreach ($data as $item){
$img_path= $item['full_path'];
$img_name= $item['file_name'];
}
$cat = array(
'name' => $this->input->post('cat_title'),
'slug'=>$this->input->post('cat_slug'),
'date_created' => date('Y-m-d H:i:s'),
'system_ip'=> $_SERVER['REMOTE_ADDR'],
'img_name' =>$img_name,
'img_path'=>$img_path,
);
return $this->db->insert('app_category', $cat);
}
}
public function newcategory_parttwo($cat_id)
{
$this->load->helper('url');
$this->load->helper('date');
$cat_second = array(
'cat_id' =>$cat_id,
'name'=>$this->input->post('cat_title'),
'description'=>$this->input->post('cat_description'),
'parent'=>$this->input->post('cat_parent'),
);
return $this->db->insert('app_category_detail', $cat_second);
}
public function newcategory_partthree()
{
$this->load->helper('url');
$this->load->helper('date');
$id=$this->input->post('cat_parent_id');
$query=$this->db->query("select * from app_category where cat_id=$id");
$cat_name = $query->result_array();
foreach ($cat_name as $category) {
$name=$category['name'];
}
$cat_third = array(
'parent_cat_name'=>$name,
'status' =>1,
);
return $this->db->insert('app_category_parent', $cat_third);
}
public function showcategorydetails()
{
$query=$this->db->query("select app_category.*,app_category_detail.* FROM app_category LEFT JOIN app_category_detail ON app_category.cat_id=app_category_detail.cat_id where status=1");
return $query->result_array();
}
public function deactivate_category() {
$id=$this->uri->segment(3);
$data = array(
'status '=>0
);
$this->db->where('id', $id);
$this->db->update('app_category_detail', $data);
}
public function delete_category() {
$id=$this->uri->segment(3);
$data = array(
'status '=>2
);
$this->db->where('id', $id);
$this->db->update('app_category_detail', $data);
}
}
That's it.Enjoy.