On my category controller I am using the codeigniter library table class
Every thing is working fine but I would like to know is for each row it need to have it's own
category edit button / link. And be able to like anchor('category/update/' . $category['category_id'])
I do not know how to modify the table for that
Question How to modify the $this->table->generate to be able to add a link for each category.
![[Image: HTML_TABLE.png]]()
Model Function
Controller
Update I think I have the model correct now
Category.php (Size: 2.24 KB / Downloads: 3)
Every thing is working fine but I would like to know is for each row it need to have it's own
category edit button / link. And be able to like anchor('category/update/' . $category['category_id'])
I do not know how to modify the table for that
Question How to modify the $this->table->generate to be able to add a link for each category.
![[Image: HTML_TABLE.png]](http://s25.postimg.org/dv616zre7/HTML_TABLE.png)
Model Function
PHP Code:
public function get_categories() {
$this->db->select('*');
$this->db->from($this->db->dbprefix . 'category');
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result_array();
} else {
return false;
}
}
Controller
PHP Code:
<?php
class Category extends MY_Controller {
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
}
public function index() {
$this->dynamic->set_title('Category');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'active' => '',
'href' => anchor('admin/dashboard', 'Home')
);
$data['breadcrumbs'][] = array(
'active' => 'class="active"',
'href' => 'Category'
);
$this->load->library('table');
$template = array(
'table_open' => '<table class="table table-striped table-bordered">',
'thead_open' => '<thead>',
'thead_close' => '</thead>',
'heading_row_start' => '<tr>',
'heading_row_end' => '</tr>',
'heading_cell_start' => '<th>',
'heading_cell_end' => '</th>',
'tbody_open' => '<tbody>',
'tbody_close' => '</tbody>',
'row_start' => '<tr>',
'row_end' => '</tr>',
'cell_start' => '<td>',
'cell_end' => '</td>',
'row_alt_start' => '<tr>',
'row_alt_end' => '</tr>',
'cell_alt_start' => '<td>',
'cell_alt_end' => '</td>',
'table_close' => '</table>'
);
$this->table->set_heading(array('Category ID', 'Parent ID', 'Category Name', 'Category URL', 'Category Status', 'Category Date Added', 'Category Edit'));
$this->table->set_template($template);
$data['categories'] = $this->table->generate($this->get_categories());
$data['header'] = Modules::run('admin/common/header/index');
$data['footer'] = Modules::run('admin/common/footer/index');
$data['timeout'] = Modules::run('admin/common/timeout/index');
$data['navbar'] = Modules::run('admin/common/navbar/index');
$this->load->view('template/catalog/category_view', $data);
}
public function get_categories() {
$this->db->select('*');
$this->db->from($this->db->dbprefix . 'category');
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result_array();
} else {
return false;
}
}
}
Update I think I have the model correct now
PHP Code:
public function get_categories() {
$this->db->select('*');
$this->db->from($this->db->dbprefix . 'category');
$query = $this->db->get();
if ($query->num_rows() > 0) {
foreach ($query->result_array() as $result) {
$data[] = array(
'categor_id' => $result['category_id'],
'parent_id' => $result['parent_category_id'],
'name' => $result['name'],
'url' => $result['url'],
'status' => $result['status'],
'date_added' => $result['date_added'],
'category_edit' => anchor('admin/category/update/' . $result['category_id'], 'Edit')
);
}
} else {
return false;
}
return $data;
}
