title: trying making a like button in codeigniter
body: <p>When I press the button of the likes nothing happens
  can you help ?
  and which is better ? to make it like this way or to make it a href button
  and but the href link to the function.
  when I call function via the url an error accrued</p>
  
  <pre><code>Object of class profiles could not be converted to string
  </code></pre>
  
  <p><strong>Ajax</strong></p>
  
  <pre><code> &lt;script type="text/javascript"&gt;
    $(document).ready(function() {
      $("#likebtn").click(function() {
  
        $.post(
          "&lt;?php echo site_url('profiles/addlike'); ?&gt;",
          function(data) {
  
            if (data.st == 0) {
              $('#likedata').html(data.msg);
            } else if (data.st == 1) {
              $("#Likes").text(st.numLikes);
            }
          },
          'json'
        );
        return false;
      });
  
  
    });
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>&lt;p&gt; &lt;input type="button" id="likebtn" class="btn btn-default btn-lg" value="إعجاب"&gt;&lt;/p&gt;
  &lt;span class="label label-default" id="Likes"&gt;&lt;?php echo $numlikes; ?&gt;&lt;/span&gt;
  &lt;div id="likedata"&gt;&lt;/div&gt;
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>    public function checklike($user_id, $profile_id) {
          $condition = "user_id =" . "'" . $user_id . "' AND " . "profile_id =" . "'" . $profile_id . "'";
          $this-&gt;db-&gt;select('*');
          $this-&gt;db-&gt;from('likes');
          $this-&gt;db-&gt;where($condition);
          $this-&gt;db-&gt;limit(1);
          $query = $this-&gt;db-&gt;get();
  
          if ($query-&gt;num_rows() == 1) {
              return TRUE;
          } else {
              return false;
          }
      }
  
      public function addlike($user_id, $profile_id) {
          $data = array(
              'user_id' =&gt; $user_id,
              'type' =&gt; 'profile',
              'profile_id' =&gt; $profile_id
          );
          $this-&gt;db-&gt;insert('likes', $data);
      }
  
      public function read_user_information_profile($profile_id) {
          $condition = "user_id =" . "'" . $profile_id . "'";
          $this-&gt;db-&gt;select('*');
          $this-&gt;db-&gt;from('users');
          $this-&gt;db-&gt;where($condition);
          $this-&gt;db-&gt;limit(1);
          $query = $this-&gt;db-&gt;get();
  
          if ($query-&gt;num_rows() == 1) {
              return $query-&gt;result();
          } else {
              return false;
          }
      }
  
      public function likes_profile($profile_id) {
          $this-&gt;db-&gt;count_all();
          $this-&gt;db-&gt;from('likes');
          $this-&gt;db-&gt;where('profile_id', $profile_id);
          $query = $this-&gt;db-&gt;get();
  
          return $query-&gt;num_rows();
      }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>&lt;?php
  
  if (!defined('BASEPATH'))
      exit('No direct script access allowed');
  
  class profiles extends CI_Controller {
  
      public $profile_id;
  
      function __construct() {
          parent::__construct();
          $this-&gt;profile_id = $this-&gt;uri-&gt;segment(2, 9);
          $user_id = ($this-&gt;session-&gt;userdata['logged_in'] ['user_id']);
      }
  
      public function index() {
  
          $this-&gt;load-&gt;model('shoghl_profilat_model');
          $data = array();
  
          $result = $this-&gt;shoghl_profilat_model-&gt;read_user_information_profile($this-&gt;profile_id);
          $countlike = $this-&gt;shoghl_profilat_model-&gt;likes_profile($this-&gt;profile_id);
          $countads = $this-&gt;shoghl_profilat_model-&gt;ads_profile($this-&gt;profile_id);
          $level = $this-&gt;shoghl_profilat_model-&gt;level_profile($this-&gt;profile_id);
  
  
          $data = array(
              'username' =&gt; $result[0]-&gt;username,
              'fname' =&gt; $result[0]-&gt;fname,
              'mob' =&gt; $result[0]-&gt;mob,
              'lname' =&gt; $result[0]-&gt;lname,
              'numlikes' =&gt; $countlike,
              'numads' =&gt; $countads,
              'levelname' =&gt; $level
          );
          $this-&gt;load-&gt;view('profiles_view', $data);
      }
  
      public function addlike() {
          $checklike = $this-&gt;$this-&gt;shoghl_profilat_model-&gt;checklike($user_id, $this-&gt;profile_id);
          if ($checklike == FALSE) {
              $this-&gt;shoghl_profilat_model-&gt;addlike($user_id, $this-&gt;profile_id);
              $numLikes = $this-&gt;shoghl_profilat_model-&gt;likes_profile($this-&gt;profile_id);
  
              $output = array('st' =&gt; 1);
              echo json_encode($output);
          } else {
  
              $outputS = array('st' =&gt; 0, 'msg' =&gt; "you already likes this profile");
  
              echo json_encode($output);
          }
      }
  
  }
  </code></pre>
  
  <p>thanks in advance</p>