This repository has been archived by the owner on Oct 8, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #133 refactor controllers/subcategory
- Loading branch information
1 parent
5db5a1a
commit 28c911c
Showing
1 changed file
with
31 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,50 @@ | ||
<?php | ||
class Subcategory extends MY_Controller{ | ||
|
||
function __construct(){ | ||
class Subcategory extends MY_Controller | ||
{ | ||
|
||
function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->load->model("subcategory_model","subcategory"); | ||
$this->load->model('subcategory_model', 'subcategory'); | ||
} | ||
|
||
function update_value() | ||
{ | ||
$id = $this->input->post ( "id" ); | ||
$value = urldecode ( $this->input->post ( "value" ) ); | ||
$field = $this->input->post ( "field" ); | ||
$values = array ( | ||
$field => $value | ||
); | ||
$output = $this->subcategory->update ( $id, $values ); | ||
|
||
|
||
echo $output; | ||
$id = $this->input->post('id'); | ||
$value = urldecode($this->input->post('value')); | ||
$field = $this->input->post('field'); | ||
$values = [ | ||
$field => $value | ||
]; | ||
$output = $this->subcategory->update($id, $values); | ||
|
||
print $output; | ||
} | ||
function create($category_id) | ||
|
||
function create($category_id) | ||
{ | ||
$this->load->model ( 'category_model', 'category' ); | ||
$this->load->model('category_model', 'category'); | ||
$category = $this->category->get($category_id); | ||
$data['category_id'] = $category_id; | ||
$data ['title'] = sprintf('Create a New Subcategory for %s',$category->category); | ||
$data ['target'] = 'subcategory/edit'; | ||
$data ['action'] = 'insert'; | ||
$data ['subcategory'] = FALSE; | ||
if ($this->input->get ( 'ajax' )) { | ||
$this->load->view ( 'page/modal', $data ); | ||
$data['title'] = sprintf('Create a New Subcategory for %s', $category->category); | ||
$data['target'] = 'subcategory/edit'; | ||
$data['action'] = 'insert'; | ||
$data['subcategory'] = FALSE; | ||
if ($this->input->get('ajax')) { | ||
$this->load->view('page/modal', $data); | ||
} else { | ||
$this->load->view ( 'page/index', $data ); | ||
$this->load->view('page/index', $data); | ||
} | ||
} | ||
|
||
function insert() | ||
{ | ||
if ($subcategory = $this->input->post ( 'subcategory' )) { | ||
if ($subcategory = $this->input->post('subcategory')) { | ||
$category_id = $this->input->post("category_id"); | ||
if (! $this->subcategory->exists ($category_id, $subcategory )) { | ||
$this->subcategory->insert ( $category_id, $subcategory ); | ||
if (!$this->subcategory->exists($category_id, $subcategory)) { | ||
$this->subcategory->insert($category_id, $subcategory); | ||
} | ||
} | ||
redirect ( 'category' ); | ||
redirect('category'); | ||
} | ||
} | ||
} |