I got a problem with my custom MVC code:
Fatal error: Uncaught Error: Cannot call constructor in C:\xampp\htdocs\phpmvc3\app\controller\admin.php:6 Stack trace: #0 C:\xampp\htdocs\phpmvc3\app\core\App.php(18): Admin->__construct() #1 C:\xampp\htdocs\phpmvc3\public\index.php(5): App->__construct() #2 {main} thrown in C:\xampp\htdocs\phpmvc3\app\controller\admin.php on line 6
Here's the code in App.php
<?php
class App {
protected $controller = 'Home';
protected $method = 'index';
protected $params = [];
public function __construct() {
$url = $this->parseURL();
if (!empty($url) && file_exists('../app/controller/' . $url[0] . '.php')) {
$this->controller = $url[0];
unset($url[0]);
}
require_once '../app/controller/' . $this->controller . '.php';
$this->controller = new $this->controller;
if (!empty($url) && isset($url[1])) {
if (method_exists($this->controller, $url[1])) {
$this->method = $url[1];
unset($url[1]);
}
}
// Params
$this->params = !empty($url) ? array_values($url) : [];
// Jalankan controller method dan kirimkan params jika ada
call_user_func_array([$this->controller, $this->method], $this->params);
}
public function parseURL() {
if (isset($_GET['url'])) {
$url = rtrim($_GET['url'], '/');
$url = filter_var($url, FILTER_SANITIZE_URL);
$url = explode('/', $url);
return $url;
}
return [];
}
}
So I tried to load a library with using this code:
class Admin extends Controller{
public function __construct()
{
parent::__construct();
$this->load->library('form_validation');
}
I wanted to load library but I'm not using CI3, I'm just using the MVC