title: Codeigniter Select JSON, Insert JSON
body: <p>I have very simple users database: user_id, user_name, user_email</p>
  
  <p>My model this:</p>
  
  <pre><code>class Users extends CI_Model {
  private $table;
  private $table_fields;
  private $table_fields_join;
  
  function __construct() {
      parent::__construct();
  
      $this-&gt;table = 'users';
      $this-&gt;table_fields = array(
              $this-&gt;table.'.user_id',
              $this-&gt;table.'.user_name',
              $this-&gt;table.'.user_email'
      );
      $this-&gt;table_fields_join = array();
  }
  
  function select(){
      $this-&gt;db-&gt;select(implode(', ', array_merge($this-&gt;table_fields, $this-&gt;table_fields_join)));
      $this-&gt;db-&gt;from($this-&gt;table);
  
      $query = $this-&gt;db-&gt;get();
  
      if($query-&gt;num_rows() &gt; 0){
          return $query-&gt;result();
      } else {
          return false;
      }
  }
  
  function insert($data) {
      $data = array(
         'user_name'  =&gt; $data['user_name'],
         'user_email' =&gt; $data['user_email']
      );
  
      $this-&gt;db-&gt;insert($this-&gt;table, $data);
  }
  </code></pre>
  
  <p>My controller this: </p>
  
  <pre><code>class Users extends CI_Controller { 
  
  function __construct(){
     parent::__construct();
     $this-&gt;load-&gt;model('users');
  }
  public function select(){
  $data['query'] = $this-&gt;users-&gt;select(); 
  $data = json_encode($data['query']);
  echo $data;
  }
  public function insert($json){
    $data = json_decode($json);
    $this-&gt;users-&gt;insert($data);
    }
  }
  </code></pre>
  
  <p>And this is my routing.php:</p>
  
  <pre><code>$route['default_controller'] = 'Welcome';
  $route['users'] = 'users/select';
  $route['users/insert/:(any)'] = 'users/insert';
  </code></pre>
  
  <p>I would like that 127.0.0.1/users/select give json.
  Example: [{"user_name":"user1","user_email":"user@user.de"}]</p>
  
  <p>This JSON insert my table: 127.0.0.1/users/insert/[{"user_name":"user1","user_email":"user@user.de"}]</p>
  
  <p>But my code is not working. :-(</p>