title: REST SERVER get function using CodeIgniter 3
body: <p>I'm currently studying rest api and i am using a ci framework with chris's rest server and i am having a problem with my users_get when i put the id in my links for example this,"<a href="http://localhost/api/example/users/id/1" rel="nofollow">http://localhost/api/example/users/id/1</a>" it still shows all the data from the database, is my query wrong? here.</p>
  
  <p>COntroller </p>
  
  <pre><code>public function users_get()
  {
      // Users from a data store e.g. database
      $users = 
               $result=$this-&gt;regusers-&gt;get(); 
  
  
      $id = $this-&gt;get('result');
  
      // If the id parameter doesn't exist return all the users
  
      if ($id === NULL)
      {
          // Check if the users data store contains users (in case the database result returns NULL)
          if ($users)
          {
              // Set the response and exit
              $this-&gt;response($users, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
          }
          else
          {
              // Set the response and exit
              $this-&gt;response([
                  'status' =&gt; FALSE,
                  'message' =&gt; 'No users were found'
              ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
          }
      }
  
      // Find and return a single record for a particular user.
  
      $id = (int) $id;
  
      // Validate the id.
      if ($id &lt;= 0)
      {
          // Invalid id, set the response and exit.
          $this-&gt;response(NULL, REST_Controller::HTTP_BAD_REQUEST); // BAD_REQUEST (400) being the HTTP response code
      }
  
      // Get the user from the array, using the id as key for retreival.
      // Usually a model is to be used for this.
  
      $user = NULL;
  
      if (!empty($users))
      {
          foreach ($users as $key =&gt; $value)
          {
              if (isset($value['result']) &amp;&amp; $value['result'] === $id)
              {
                  $user = $value;
              }
          }
      }
  
      if (!empty($user))
      {
          $this-&gt;set_response($user, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code
      }
      else
      {
          $this-&gt;set_response([
              'status' =&gt; FALSE,
              'message' =&gt; 'User could not be found'
          ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code
      }
  }
  </code></pre>
  
  <p>Model</p>
  
  <pre><code> &lt;?php 
  </code></pre>
  
  <p>class Regusers Extends CI_Model{</p>
  
  <pre><code>public function get(){
  
      $query=$this-&gt;db-&gt;get('tbl_user');
      return $query-&gt;result();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>View</p>
  
  <pre><code>&lt;li&gt;&lt;a href="&lt;?php echo site_url('api/example/users'); ?&gt;"&gt;Users&lt;/a&gt; - defaulting to JSON&lt;/li&gt;
          &lt;li&gt;&lt;a href="&lt;?php echo site_url('api/example/users/format/csv'); ?&gt;"&gt;Users&lt;/a&gt; - get it in CSV&lt;/li&gt;
          &lt;li&gt;&lt;a href="&lt;?php echo site_url('api/example/users/id/1'); ?&gt;"&gt;User #1&lt;/a&gt; - defaulting to JSON  (users/id/1)&lt;/li&gt;
          &lt;li&gt;&lt;a href="&lt;?php echo site_url('api/example/users/1'); ?&gt;"&gt;User #1&lt;/a&gt; - defaulting to JSON  (users/1)&lt;/li&gt;
          &lt;li&gt;&lt;a href="&lt;?php echo site_url('api/example/users/id/1.xml'); ?&gt;"&gt;User #1&lt;/a&gt; - get it in XML (users/id/1.xml)&lt;/li&gt;
          &lt;li&gt;&lt;a href="&lt;?php echo site_url('api/example/users/id/1/format/xml'); ?&gt;"&gt;User #1&lt;/a&gt; - get it in XML (users/id/1/format/xml)&lt;/li&gt;
          &lt;li&gt;&lt;a href="&lt;?php echo site_url('api/example/users/id/1?format=xml'); ?&gt;"&gt;User #1&lt;/a&gt; - get it in XML (users/id/1?format=xml)&lt;/li&gt;
          &lt;li&gt;&lt;a href="&lt;?php echo site_url('api/example/users/1.xml'); ?&gt;"&gt;User #1&lt;/a&gt; - get it in XML (users/1.xml)&lt;/li&gt;
          &lt;li&gt;&lt;a id="ajax" href="&lt;?php echo site_url('api/example/users/format/json'); ?&gt;"&gt;Users&lt;/a&gt; - get it in JSON (AJAX request)&lt;/li&gt;
          &lt;li&gt;&lt;a href="&lt;?php echo site_url('api/example/users.html'); ?&gt;"&gt;Users&lt;/a&gt; - get it in HTML (users.html)&lt;/li&gt;
          &lt;li&gt;&lt;a href="&lt;?php echo site_url('api/example/users/format/html'); ?&gt;"&gt;Users&lt;/a&gt; - get it in HTML (users/format/html)&lt;/li&gt;
          &lt;li&gt;&lt;a href="&lt;?php echo site_url('api/example/users?format=html'); ?&gt;"&gt;Users&lt;/a&gt; - get it in HTML (users?format=html)&lt;/li&gt;
  </code></pre>