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);
}
当我在控制器中打印$user_list
像这样print_r($user_list);
我在数组中获取值。在视图中我试图使用for循环迭代并打印变量。但是我收到此错误“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;
?>