2016-09-22 28 views
-1

enter image description here我想顯示錶使用codeigniter和angularjs從MySQL數據庫我做錯了什麼? 這是我的看法:list_show_data.php如何解決這個消息?嚴重性:通知 - >未定義的屬性:stdClass ::

<?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 
+0

檢查你的stlc_users表,你可能有錯誤的列。 'var_dump($ r)'也可以幫助 – aynber

+0

顯然這是:'$ data_arr [$ i] ['First Name'] = $ r-> First'。做過任何基本的調試,比如檢查'$ r'中的內容? –

+0

@MarcB,'$ r'是'foreach($ res爲$ r)提供的當前值' – DFriend

回答

2

此錯誤消息表示$r對象,它表示從您的數據庫表stlc_users,沒有這兩個屬性:LastUser。最可能的原因是數據庫表中沒有包含這些名稱的列。

+0

我添加了圖像鏈接,似乎我已設置。你可以明顯地告訴我,我是一個新手。 – excelsiorone

+1

您的列名是「First_Name」,「Last_Name」和「User_Name」。我不是100%確定的,但也許在'_'附近還包含空格字符。如果是這樣,請重命名您的列名稱,排除空格字符。然後你可以在你的代碼中使用'$ r-> First_Name','$ r-> Last_Name'和'$ r-> User_Name'。 –

+0

謝謝!我得到它的工作!你搖滾 – excelsiorone

相關問題