view raw
Jasper VB Jasper VB - 8 months ago 26
PHP Question

Use codeiginiter and ajax following the rules codeigniter

I'm struggeling to use codeigniter the way it was created. I'm opening an edit page (order). I want to change data on the page which will be dynamically saved after leaving a field. But when I'm not succeeding in the way codeigniter works or with other words on a "nice way". I don't want to be depending on the uri structure and get the data with uri segment, like the code is now. I want to improve the code beneath but i'm not succeeding...

This is the code to open my view

public function edit($id = NULL) {
// Fetch a page or set a new one
$this->data['subtitle'] = 'incoming';
if ($id) {
if($this->transfer_m->get_permission($id) > 0){
$this->data['transfer'] = $this->transfer_m->get_rec($id);
// $this->data['transfer'] = $this->transfer_m->get($id,true);
count($this->data['transfer']) || $this->data['errors'][] = 'page could not be found';
$this->data['details'] = $this->details_m->get_by(array('doc_no' => $id),FALSE);
redirect('admin/Dashboard', 'refresh');
} else {
$this->data['transfer'] = $this->transfer_m->get_new();

$this->data['shop_from'] = $this->shop_m->get($this->data['transfer']->from_customer,TRUE);
$this->data['shop_to'] = $this->shop_m->get($this->data['transfer']->to_customer,TRUE);

// Load the view
$this->data['subview'] = 'pages/details/transfer_edit';
$this->load->view('pages/main', $this->data);


My ajax call

function add_shop(shop){
var id = $('#doc_no').text();

url: base_url+"/admin/transfer/add_shop/"+id+"/"+shop,
async: false,
type: "POST",
data: "",
dataType: "html",
success: function(data) {


my controller function to add a shop

public function add_shop($id){
$data = array('to_customer' => $this->uri->segment(5));


Any help will be appreciated!!


You can use post. Modify your ajax call and pass the data like below. See the document here

 data: { id: id, shop: shop }

This data can be accessed $this->input->post('id'); $this->input->post('shop');