Не получается передать массив в view
Здравствуйте.
Контроллер Welcome:
class Welcome extends CI_Controller {
public function index()
{
$this->load->view('users_view');
}
function users()
{
$this->load->model('users_model');
$data['users'] = $this->users_model->get_users();
$this->load->view('users_view', $data);
}
Модель:
<?php
class Users_model extends CI_Model {
function get_users()
{
$query = $this->db->get('users');
return $query->result_array();
}
}
?>
сам View:
<html>
<head>
<title>тест</title>
</head>
<body>
<?php
if (is_array($users))
{
foreach($users as $item)
{
echo $item['id'];
echo $item['login'];
echo $item['name'];
}
}
?>
</body>
</html>
выдает ошибку " Undefined variable: users"
В чем может быть проблема?
Источник: Stack Overflow на русском