javascript - AngularJS resource + Slim Framework only gets a single data -


i'm creating restful single page application using slim framework end , angularjs front end. far, create, retrieve all, , delete working when try retrieve single data, single field works. here code:

studentcontroller.js

angular     .module('studentinfoapp')     .factory('student', student)     .controller('studentscontroller', studentscontroller)     .config(config);  function config($routeprovider) {     $routeprovider     .when('/', {         controller: 'studentscontroller',         templateurl: 'app/views/student-list.html'     });  }  function student($resource) {     //return $resource('/students/:id');     return $resource("/students/:id", {}, {     query: { method: "get", isarray: true }   });  } function studentscontroller(student, $scope, $http) {      $scope.inputform = {};     $scope.students = null;      function clearinput() {         $scope.inputform = {             fname: '',             lname: '',             age: '',             email: ''         }     }      function initstudents() {         student.query(function(data, headers) {             $scope.students = data;             $scope.studentspanel = true;             console.log(data);         }, function (error) {             console.log(error);         });     }      initstudents();      $scope.editstudent = function(id) {         student.query({ id: id }, function(data, headers) {             $scope.student = data;             console.log(data);             $scope.dataform = true;         }, function (error) {             console.log(error);         });      }  } 

index.php (slim)

$app->get('/students/:id', 'getstudent'); function getstudent($id) {     $app = \slim\slim::getinstance();     try {         $db = getconnection();         $query = $db->prepare("select * students id=?");         $query->execute(array($id));         $stmt = $query->fetchall(pdo::fetch_assoc);         $data = json_encode($stmt);         echo $data;     } catch(pdoexception $e) {         echo '{"error":{"text":'. $e->getmessage() .'}}';      } } 

student-list.html

<!--edit form--> <div class="col s12" ng-show="dataform" ng-repeat="x in student">   <div class="row">     <div class="input-field col l6 s12">       <input id="first_name" value="{{ x.fname }}" type="text" class="validate" ng.model="editform.fname">       <label class="active" for="first_name">first name</label>     </div>     <div class="input-field col l6 s12">       <input id="last_name" value="{{ x.lname }}" type="text" class="validate" ng-model="editform.lname">       <label class="active"  for="last_name">last name</label>     </div>   </div>   <div class="row">     <div class="input-field col l6 s12">       <input id="email" value="{{ x.email }}" type="email" class="validate" ng-model="editform.email">       <label class="active"  for="email">e-mail address</label>     </div>     <div class="input-field col l6 s12">       <input id="age" value="{{ x.age }}" type="text" class="validate" ng-model="editform.age">       <label class="active"  for="age">age</label>     </div>   </div>   <button class="btn waves-effect waves-light" ng-click="updatestudent()">submit   <i class="material-icons right">send</i>   </button>   <button class="btn waves-effect waves-light pink accent-3" ng-click="canceleditstudent()">cancel</button> </div> <!-- form --> <table class="highlight responsive-table">   <thead>     <tr>       <th>name</th>       <th>age</th>       <th>email</th>       <th>action</th>     </tr>   </thead>   <tbody>     <tr ng-repeat="s in students | filter:searchstudent" ng-show="studentspanel">       <td>{{ s.fname }} {{ s.lname }}</td>       <td>{{ s.age }}</td>       <td>{{ s.email }}</td>       <td><a href="javascript:void(0)" ng-click="editstudent(s.id)">edit</a> <a href="javascript:void(0)" ng-click="deletestudent(s.id)">delete</a></td>     </tr>   </tbody> </table> 

when run it, page:

enter image description here

and when click edit, shows:

enter image description here

as can see, first name being populated though correct (field name, etc..) , console returns no error.

am missing here? appreciated. got stuck already.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -