未定义的类属性

///DATA MODEL
class Data extends CI_Model{
    function __construct() {
        parent::__construct();
    }
    function read_record(){
        $q = $this->db->get('category');
        return $q->result();
    }
}

//in Controller
class Test_admin extends CI_Controller{
    function index(){
        $this->load->model('data');
        $dat = array();
        if( $q = $this->data->read_record()){
         $dat['record'] = $q;
        }
        $this->load->view('test', $dat);
    }
}

// in view
<?php
foreach ($record as $row){
    echo $row->name;
    echo '<br />';
}  
?>

Error shown:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$name

Filename: views/test.php

Line Number: 35

Backtrace:

File: C:\wamp\www\ci312\application\views\test.php Line: 35 Function: _error_handler

File: C:\wamp\www\ci312\application\controllers\test_admin.php Line: 9 Function: view

File: C:\wamp\www\ci312\index.php Line: 315 Function: require_once

Add in a var_dump() in your view code to examine what you are passing in...

in view

 <?php

 var_dump($record); // Debug
 exit(); // Debug
 foreach ($record as $row){
    echo $row->name;
    echo '<br />';
 }