title: what's the best way to integrate dataTables with cakePhp using the MVC approach
body: <p>I've done up a bit of code in which I attempt to integrate data tables (http://datatables.net/) with cakePHP.</p>
  
  <p>It's up and running with my own app, but I want to make it more generic, so it can be used by anyone across any cakePhp application, and most importantly I want it to fit in with cakePHP conventions.</p>
  
  <p>So at the moment this is what I have...</p>
  
  <p>A cakePHP helper called <code>dataTables</code>, which takes the following arguments: <code>$modelName</code>, <code>$fields</code>, <code>$headers</code>.</p>
  
  <ul>
  <li><code>$modelName</code> is the name of the model whose data will be populating the table.</li>
  <li><code>$fields</code> is an array of fields we want to show in the table (all fields must be prepended with "ModelName." which means we can show associated model values in the table)</li>
  <li><code>$headers</code> is a list of headers we want to be displayed at the top of the table.</li>
  </ul>
  
  <p>The helper produces an empty html table (with the <code>$headers</code> as headers). The table is then populated by datables' javascript (you might have to read up on <a href="http://datatables.net/release-datatables/examples/server_side/server_side.html" rel="nofollow">this</a> if you're not familiar with dataTables server-side processing).</p>
  
  <p>The Javascript retrieves the table data from the <code>dataTable()</code> action of the controller whose model we want to get at. The javascript will also send the model name (which we sent to the helper), and the fields. The controller then prints out the JSON data (through a blank view)</p>
  
  <p>My two main questions are:</p>
  
  <ol>
  <li><p>It doesn't seem right to place the dataTable action in a controller. A) because it doesn't actually need the controller because it knows what model and fields it needs to load and B) because it's not really a <strong>user</strong> action, its really just a JSON response. So where should it be put?</p></li>
  <li><p>To print the JSON repsonse for my <code>dataTable()</code> action, I use a "<code>blank.ctp</code>" view and the use <code>echo jsonencode($output)</code>. It doesn't seem right to use a view to output JSON data. Usually views are just for the user right?</p></li>
  </ol>
  
  <p>One way of answering both of these questions is to have a standalone <code>dataTable.php</code> file, which will print the relevant JSON data based on the model name and fields it receives.
  But this ^^ doesn't seem logical considering the MVC pattern.</p>
  
  <p>The code is a bit messy at the moment (answers to the above should help me tidy it up!) but let me know if need to see.</p>
  
  <p>Hope this makes sense to someone other then myself..</p>