title: REST API with CodeIgniter
body: <p>I am creating a web-service backend for a mobile app I am developing. (I am an experience Obj-C developer, not a web-designer!) Essentially I would like to use Codeigniter and Phil Sturgeon's RESTful API Server <a href="https://github.com/philsturgeon/codeigniter-restserver" rel="noreferrer">https://github.com/philsturgeon/codeigniter-restserver</a> however, I'm having some trouble getting it all setup and working. </p>
  
  <p>I have MySQL database that is setup with data in it. And I need some help writing a CodeIgniter PHP model and controller that returns JSON data of what is inside that database. All of the tutorials and forum post's i have found deal with hardcoded data in the controler, not a MySQL database. I would ideally like to have the URL formatted like this <a href="http://api.mysite.com/v1/search?id=1&amp;name=foo&amp;city=bar" rel="noreferrer">http://api.mysite.com/v1/search?id=1&amp;name=foo&amp;city=bar</a> , I could potentially have 50+ parameters to pass in the url.</p>
  
  <p>Using Phil's code, I have come up with this as my controller: </p>
  
  <pre><code>public function index_get()
  {
      if (!$this-&gt;get('id'))
      {
          $this-&gt;response(NULL, 400);
      }
  
      $data = $this-&gt;grid_m-&gt;get_id($this-&gt;get('id'));
      if ($data)
      {
          $this-&gt;response($data, 200);
      }
      else
      {
          $this-&gt;response(NULL, 404);
      }
  }
  </code></pre>
  
  <p>That only gets me one search term: id?=# .. I need to know how to get multiple search terms</p>
  
  <p>Here is my Codeigniter model:</p>
  
  <pre><code>&lt;?php
  
  class Grid_m extends CI_Model
  {
  
  function get_all()
  {
      $query = $this-&gt;db-&gt;get('grid');
      if ($query-&gt;num_rows() &gt; 0)
      {
          return $query-&gt;result();
      }
      return FALSE;;
  }
  </code></pre>
  
  <p>This just returns EVERYTHING in my MySQL database regardless of what id or url term I pass it in the URL.</p>
  
  <p>I'm a big noob when it comes to developing my own custom API so any suggestions on how to fix my controller and database model would be a huge help!</p>
  
  <p>Thanks for the help!</p>
  
  <p>-brian</p>