Welcome Guest, Not a member yet? Register   Sign In
How to differentiate between controller files/controller methods/ and controller parameters in a url.
#1

[eluser]lanzd[/eluser]
I'm trying to use ajax in a codeigniter application but I don't know how to tell codeigniter what to use in my url as a file/method/parameter.

I have a file located here: application/controllers/admin/manage.php

In that file I have a method:

Code:
public function edit_section($section) { }

and I have another method:

Code:
public function ajax_edit_section() { }

I start out in the first method and when the form is submitted I use ajax to submit the form. Ajax then called the 2nd method to insert the data and echo "successful", if it is successful and echo "Failure" if it fails.

My jquery ajax files are as so:

Code:
function formSend(url, status, table, id, date, body1){

        $.ajax({
  type: "POST",
  url:url,
  dataType: 'html',
  data: {table: table, id: id, date: date, body1: body1},
  success: function (data){
   if(typeof(data.error) != 'undefined') {
    if(data.error != '')
    
                                        alert(data.error);
   } else {
                                            
     alert(data);
                                        $('#'+status).html('data');
                                        $('#'+id+'-body1').html('body1');
                                        $('#'+id+'-date').html('date');
                                        
   }
  }
});
}

$(document).ready(function () {
    
$("[id*='-submit']").live("click", function(e) {
  
                e.preventDefault();
                
                var id_button = $(this).attr("id").toLowerCase();
                var btnArray = id_button.split('-');
                
              
              
                var table = $("#"+id+"-table").attr("value");          
                var id = btnArray[0];
  var date = $("#"+id+"-date").attr("value");            
  var body1 = $("#"+id+"-body1").attr("value");            
      
                var button_val = $(this).attr("value").toLowerCase();
  var id_video = id_button.split('-');

                var url = "ajax_edit_section";
                
                formSend(url, "msg", table, id, date, body1);
});
});

Whats happening is, it is taking the value of "url" and using it as the variable to

Code:
public function edit_section($section) { }

How do I tell codeigniter to use it differently? The only Idea I have is if I create a hidden field in my form and give it an absolute path using
Code:
<?php echo base_url(); ?>
and grabbing that value via jquery.

I feel there has got to be a better way to do it though, because I really don't want to have my folder structures exposed like that for anyone to see.

Thanks, Dan

_____________________________________________________
Edit: I forgot to add, I also tried changing this line
Code:
var url = "ajax_edit_section";
to this
Code:
var url = "/admin/manage/ajax_edit_section";

and it does the same thing, the url it goes to is "/admin/manage/admin/manage/ajax_edit_section"


Messages In This Thread
How to differentiate between controller files/controller methods/ and controller parameters in a url. - by El Forum - 03-05-2012, 04:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB