title: jquery autocomplete with codeigniter - passing controller name to javascript
body: <p>I have a codeigniter autocomplete working correctly. The javascript syntax is:</p>
  
  <p><em>controller</em></p>
  
  <pre><code>  function autocomplete(){
      $this-&gt;load-&gt;view('sales/new_order_details');
    }
  </code></pre>
  
  <p><em>model</em></p>
  
  <pre><code>function get_customer($q){
      $this-&gt;db-&gt;select('CustomerName');
      $this-&gt;db-&gt;like('CustomerName', $q);
      $query = $this-&gt;db-&gt;get('Customers');
      if($query-&gt;num_rows &gt; 0){
        foreach ($query-&gt;result_array() as $row){
          $row_set[] = htmlentities(stripslashes($row['CustomerName'])); //build an array
        }
        $this-&gt;output-&gt;set_content_type('application/json')-&gt;set_output(json_encode($row_set));
  
      }
    }
  </code></pre>
  
  <p><em>javascript</em></p>
  
  <pre><code>$(function(){
    $("#customer").autocomplete({
      source: "get_customers"
    });
  });
  </code></pre>
  
  <p>The concept of the MVC framework is reuseability. How can I pass the name of the requesting controller to the javascript so it can be dynamically used by several controller methods?</p>
  
  <p>So something like:</p>
  
  <pre><code>var method=controllername.requestingmethod;
  $(function(){
    $("#customer").autocomplete({
      source: "method"
    });
  });
  </code></pre>
  
  <p>Any ideas?</p>