OMENSAH
4/27/2018 - 5:32 AM

barePHP.php

<?php 
  class User{
        private $db;
        public function __construct(Database $database){
            $this->db = $database;
        }
        public function getUsers(){
            $this->db->query("SELECT * FROM users");
            return $this->db->resultSet();
        }
    }
    
    
<?php 
    class Users extends BaseController{
        public function __construct(){ 
            $this->modelDB = $this->loadModel("User");
        }
        public function index(){
            $users = $this->modelDB->getUsers();
            var_dump($users);
            $data = [
                "title" =>  "My Users",
                "users" => $users
            ];
            $this->loadView('pages/index', $data);
        }
    }
    
        <h1><?php echo $data['title']; ?></h1>
        <?php foreach($data['users'] as $user): ?>
            <li><h1><?php echo $user->name; ?></h1></li>
         <?php endforeach; ?>