2014-02-18 21 views
0

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); 
    } 

财产迭代使用循环和打印他变量。但我得到这个错误“ErrorException [ Notice ]: Trying to get property of non-object”。如果我打印该变量为$user_list,它正在打印为数组。

views.php

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

这意味着你的'$ user_list'数组中的内容都不是对象。 – thatidiotguy

+0

@thatidiotguy你能告诉我如何解决这个问题。 – user2681579

+0

我没有什么可以说的,以帮助你解决这个问题,我告诉过你你遇到的问题。 – thatidiotguy

回答

1

使用as_object方法:

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

ORM

$user_list = ORM::factory('User')->find_all(); 
相关问题