简体   繁体   中英

ErrorException [ Notice ]: Trying to get property of non-object

controller.php

public function action_user() {
        $user_list = DB::select()->from('users')->execute();
//       print_r($user_list);
        $this->template->content = View::factory('user')
                                    ->bind('user_list',$user_list);
    }

when i print the $user_list in controller like this print_r($user_list); i am getting the values in array.In views i am trying to iterate using for loop and printing he variable.But i am getting this error " ErrorException [ Notice ]: Trying to get property of non-object ".If i print the variable as $user_list ,it is printing as array.

views.php

 <?php echo $user_list; ?> //printing array
    <?php
        foreach ($user_list as $user):
        echo $user->username;  //getting error here
        endforeach;
    ?>

Using the as_object method:

$user_list = DB::select()->from('zid_users')->as_object('User')->execute();

or the ORM

$user_list = ORM::factory('User')->find_all();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM