如何修复此消息?严重性:通知 - >未定义的属性:stdClass ::

时间:2016-09-22 14:57:47

标签: mysql angularjs codeigniter

enter image description here我试图使用codeigniter和angularjs从mysql db显示表我做错了什么? 这是我的观点:list_show_data.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html ng-app="app">
<head>
<meta charset="utf-8">
<title>List Show Data</title>

<link rel="stylesheet" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

</head>
<body>

<div ng-controller="decontroller">
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Role</th>
<th>Privileges</th>
<th>User Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="n in list_data">
    <td>{{n.First Name}}</td>
    <td>{{n.Last Name}}</td>
    <td>{{n.Email}}</td>
    <td>{{n.Role}}</td>
    <td>{{n.Privileges}}</td>
    <td>{{n.User Name}}</td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript" href="/public/js/angular.js"> </script>
<script type="text/javascript"    src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js">  </script>
<script type="text/javascript">
var app = angular.module('app',[]);
app.controller('decontroller', function($scope,$http){
    $scope.list_data=[];
    $http.get("ajax_load_data").success(function(result){
        $scope.list_data=result;
    });
});
</script>
</body>
</html>

这是我的控制器:MainTest.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class MainTest extends CI_Controller {

/**
 * Index Page for this controller.
 *
 * Maps to the following URL
 *      http://example.com/index.php/welcome
 *  - or -
 *      http://example.com/index.php/welcome/index
 *  - or -
 * Since this controller is set as the default controller in
 * config/routes.php, it's displayed at http://example.com/
 *
 * So any other public methods not prefixed with an underscore will
 * map to /index.php/welcome/<method_name>
 * @see https://codeigniter.com/user_guide/general/urls.html
 */
public function list_show_data()
{

    $this->load->helper('url');
    $this->load->view('list_show_data');

}

public function ajax_load_data()
{
    $this->load->helper('url');
    $res = $this->db->get('stlc_users')->result();
    $data_arr = array();
    $i=0;
    foreach($res as $r)
    {
        $data_arr[$i]['First Name'] = $r->First  ;
        $data_arr[$i]['Last Name'] = $r->Last  ;
        $data_arr[$i]['Email'] = $r->Email;
        $data_arr[$i]['Role'] = $r->Role;
        $data_arr[$i]['Privileges'] = $r->Privileges;
        $data_arr[$i]['User Name'] = $r->User  ;
        $i++;
    }
    echo json_encode($data_arr);
}

}

这是我得到的错误:

Severity: Notice --> Undefined property: stdClass::$First C:\xampp\htdocs\stlc\application\controllers\MainTest.php 38
ERROR - 2016-09-22 16:31:19 --> Severity: Notice --> Undefined property: stdClass::$Last C:\xampp\htdocs\stlc\application\controllers\MainTest.php 39
ERROR - 2016-09-22 16:31:19 --> Severity: Notice --> Undefined property: stdClass::$User C:\xampp\htdocs\stlc\application\controllers\MainTest.php 43

1 个答案:

答案 0 :(得分:2)

此错误消息表示$r对象(表示数据库表stlc_users中的一行)不具有以下两个属性:LastUser。最有可能的原因是数据库表中没有带有这些名称的列。