I have found a mini MVC on Github which im now building on top of for my own system but right now i am experiencing errors when trying to display data on the view pages.
The URL goes like this → https://domain.com/user/profile/admin
Unfortunately I get this error which i’m really confused about.
Array ( [:username] => admin ) SELECT * FROM jh_users WHERE username = :username;
Warning: Invalid argument supplied for foreach() in /customers/a/d/5/domain.com/httpd.www/app/core/Controller.php on line 36 Warning: Invalid argument supplied for foreach() in /customers/a/d/5/domain.com/httpd.www/app/helpers/view.php on line 18
Current version is PHP 7.1.16 - Warning: Invalid argument supplied for foreach() in /customers/a/d/5/domain.com/httpd.www/app/helpers/view.php on line 18
Here my code for the view.php:
function extend_view($paths, $data)
{
// Set each index of data to its named variable.
foreach($data as $key => $value) {
$$key = $value;
}
foreach ($paths as $path) {
include (VIEWS_PATH . $path . '.php');
}
}
Here is my controller code:
<?php if (!defined('BASE_PATH')) exit('No direct script access allowed');
class User extends Controller
{
public $user;
public function __construct()
{
$this->load_helper(['view']);
$this->user = $this->model('Users'); // Instantiate a new user object.
}
public function index($param1 = '', $param2 = '')
{
$this->view('home');
}
// Show our User Profile report
public function profile($user_id)
{
// Get the user by id. (much cleaner)
$data = $this->user->getUserByUserId($user_id);
// Load the View passing to it the Users information as $data.
$this->view('user/profile', $data);
}
}
I checked all my db connections which are fine and successful and tried it on a different host but no luck! Can anyone see what is wrong?
Thanks