|
|
|
รบกวนช่วยดู dynamic select CodeIgniter 2.0.2 ให้หน่อยคับ |
|
|
|
|
|
|
|
รบกวนช่วยดูการสร้าง dynamic select CodeIgniter 2.0.2 หน่อยครับ Code (PHP)
product_model.php
<?php
class Product_model extends CI_Model{
public $id_type;
public $id_cate;
function getcate(){
$this->db->select('id_cate,cate');
$this->db->from('tbl_cate');
$query = $this->db->get();
$categories=array();
if($query->result()){
foreach ($query->result() as $cates) {
$categories[$cates->id_cate] = $cates->cate;
}
return $categories;
}else{
return FALSE;
}
}
function gettype($id_cate){
$this->db->select('id_type,id_cate,ntype');
$this->db->from('tbl_type');
$this->db->where('id_cate',$id_cate);
//$this->db->order_by('id_type','desc');
$query = $this->db->get();
$type=array();
if($query->result()){
foreach($query->result() as $types){
$type[$types->id_type] = $types->ntype;
}
return $type;
}else{
return False;
}
}
}
Code (PHP)
product.php
<?php
class Product extends CI_controller{
function form(){
$this->load->library('ckeditor');
$this->load->library('ckFinder');
//configure base path of ckeditor folder
$this->ckeditor->basePath = base_url().'assets/ckeditor/';
$this->ckeditor->config['skin'] = "kama";
$this->ckeditor->config['uiColor'] = "#D0E5F5";
//Setting a custom toolbar
$this->ckeditor->config['width'] = "850px";
$this->ckeditor->config['height'] = "300px";
//$this->ckeditor->config['toolbar'] ="Full";
$this->ckediter->config['toolbar']=array(
array('Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates'),
array('Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo'),
array('Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt'),
array('Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton','HiddenField','/'),
array('Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat'),
array('NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl'),
array('Link','Unlink','Anchor'),
array('Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe','/'),
array('Styles','Format','Font','FontSize'),
array('TextColor','BGColor'),
array('Maximize', 'ShowBlocks','-','About'),
array('height:600,width:700'));
$this->ckeditor->config['language'] = 'en';
$this->ckfinder->SetupCKEditor($this->ckeditor,'../assets/ckfinder');
$this->load->model('product_model','t');
//$data['type']=$this->t->gettype();
$data['categories']=$this->t->getcate();
$this->load->view('view_head');
$this->load->view('view_top_menu');
$this->load->view('view_product',$data);
$this->load->view('view_footer');
}
function get_type($id_cate){
header('Content-Type: application/x-json; charset=utf-8');
echo (json_encode($this->pro_model->gettype($id_cate)));
}
}
Code (PHP)
java script
$(document).ready(function(){
$('#categories').change(function()
{
var id_cate = $('#categories').val();
$.ajax(
{
type: "POST",
url: "product/get_type/"+id_cate,
success: function(type)
{
$.each(type,function(id_type,ntype)
{
var opt = $('<option />');
opt.val(id_type);
opt.text(ntype);
$('#type').append(opt);
});
}
});
});
});
</script>
Code (PHP)
view_product.php
<?php echo form_dropdown('id_cate', $categories, '#', 'id="categories"'); ?>
<?php echo form_dropdown('id_type', $type, '#', 'id="type"'); ?>
Tag : PHP
|
|
|
|
|
|
Date :
2011-08-29 22:21:21 |
By :
incomm29 |
View :
1037 |
Reply :
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|