i'm practicing on how to use the select in the php, but why i can't display my value in my select box here in php? i'm using a codeigniter framework and here is my folder structure
- controllers
- Category.php
- models
- Model_category.php
- views
- category
- index.php
the code in the index.php was
<div class="form-group">
<label for="active">From Category:</label>
<select class="form-control" id="active" name="active">
<?php foreach ($category as $k => $v): ?>
<option value="<?php echo $v['id'] ?>"><?php echo $v['name'] ?></option>
<?php endforeach ?>
</select>
</div>
and then i have this in controllers in Category.php
public function __construct()
{
parent::__construct();
$this->not_logged_in();
$this->data['page_title'] = 'Category';
$this->load->model('model_category');
}
public function index()
{
$this->render_template('category/index', $this->data);
$category['getCategoryData'] = $this->model_category >getCategoryData();
//print_r($category);die;
//$this->load->view('category/index', $category);
}
my table name is "category" and it's row is id,name,active
i tried this
$category = $this->model_category->getCategoryData();$this->load- >view('category/index', $category);
and it's working when i print using this
print_r($category);die;
output:
Array ( [getCategoryData] => Array ( [0] => Array ( [id] => 3
[name] => Adds On [active] => 1 ) [1] => Array ( [id] => 2 [name]
=> Meals [active] => 1 ) [2] => Array ( [id] => 1 [name] =>
Drinks [active] => 1 ) ) )
but i still can't display it in the select box, when i add the load view it will return like this DataTables warning: table id=manageTable - Cannot reinitialise DataTable.
my portion of code in ajax in the category.php:
$(document).ready(function() {
$("#FileMainNav").addClass('active');
$('#categoryMainNav').addClass('active');
// initialize the datatable
manageTable = $('#manageTable').DataTable({
'ajax': base_url + 'category/fetchCategoryData',
'order': []
});
// submit the create from
$("#createForm").unbind('submit').on('submit', function() {
var form = $(this);
// remove the text-danger
$(".text-danger").remove();
$.ajax({
url: form.attr('action'),
type: form.attr('method'),
data: form.serialize(), // /converting the form data into array and sending it to server
dataType: 'json',
success:function(response) {
manageTable.ajax.reload(null, false);
if(response.success === true) {
$("#messages").html('<div class="alert alert-success alert-dismissible" role="alert">'+
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'+
'<strong> <span class="glyphicon glyphicon-ok-sign"></span> </strong>'+response.messages+
'</div>');
1条答案
按热度按时间ttp71kqs1#
我想这个例子可以帮助你:(代码点火器版本3.1.13)
产品型号:
控制器:
查看方式:
最新消息:
要在Codeigniter上使用Datatables,您可以创建如下方法:Source