Reputation: 1481
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;
?>
Upvotes: 0
Views: 2316