如何在codeigniter中的2个连接表中显示angularjs中的数据?

时间:2016-01-24 04:16:51

标签: php angularjs codeigniter

我需要从反馈表中获取用户表中的user_id,firstname,lastname和feedback_id,comment,user_id和recipe_id,其中user_id来自user,等于user表中的user_id。

review.html的

  <div class="items item item-avatar" ng-repeat="comment in feedbackdata">
  <img src="img/asd.jpg">
  <h2>{{comment.firstname}} {{comment.lastname}}</h2>// I don't know what to put here
  <p>{{comment.feedback_id}}</p>
  <p>{{comment.comment}}</p>
  <p>{{comment.user_id}}</p>
  <p>{{comment.recipe_id}}</p>

Controller.js

   .controller('CommentCtrl', function($scope, CommentList,$state,$location,SessionService,getFeedbackService) {

   $scope.userdata = SessionService.getObject('userdata');
   $scope.newComment={};
   $scope.newComment.userID =  $scope.userdata.user_id;

   getFeedbackService.all().then(function(payload) {
   $scope.feedbackdata = payload.data;
   console.log(payload);
   });

  $scope.addComment = function(){
  CommentList.add($scope.newComment);
  console.log($scope.newComment);
  };

  })

Service.js

.factory('getFeedbackService', function($http){

return {
    all: function() {
      return $http.get("http://localhost/admin-recipick/api/Main/get_feedback_data");
    }
 };
 });

main.php

    public function get_feedback_data()
{
    $postdata = json_decode(file_get_contents("php://input"));
    $feedback = $this->User_model->feedback_data();
    echo json_encode($feedback);
}

user_model.php

    public function feedback_data()
    {


    $this->db->select('*');
    $this->db->from('feedback')
    $this->db->join('user','user.user_id = feedback.user_id');
    $query = $this->db->get();
    return $query->result_array();
    }

0 个答案:

没有答案