Hey guys !
Got a problem right now, I can't fetch data from my model, operation results to an error : Call to a member function findAll() on bool
the Error is:
Fatal error: Uncaught Error: Call to a member function findAll() on bool in C:\Xampp1\htdocs\system\private\controllers\Home.php:13 Stack trace: #0 C:\Xampp1\htdocs\system\private\core\app.php(37): Home->index() #1 C:\Xampp1\htdocs\system\public\index.php(5): App->__construct() #2 {main} thrown in
C:\Xampp1\htdocs\system\private\controllers\Home.php on line
13
Here is the code:
PHP Code:
for the home.php
<?php
/**
* home controller
*/
class Home extends Controller
{
function index()
{
// code...
$user = $this->load_model('User');
$data = $user->findAll();
//$data = $user->where('id','2');
$this->view('home',['rows'=>$data]);
}
}
for app.php
PHP Code:
<?php
/**
* main app file
*/
class App
{
protected $controller = "home";
protected $method = "index";
protected $params = array();
public function __construct()
{
// code...
$URL = $this-> getURL();
IF(file_exists("../private/controllers/" .$URL[0].".php")){
$this->controller = ucfirst($URL[0]);
unset($URL[0]);
}
require "../private/controllers/" .$this->controller.".php";
$this->controller = new $this->controller();
if(isset($URL[1]))
{
if(method_exists($this->controller, $URL[1]))
{
$this->method = ucfirst($URL[1]);
unset($URL[1]);
}
}
$URL = array_values($URL);
$this->params =$URL;
call_user_func_array([$this->controller, $this->method], $this->params);
}
private function getURL()
{
$url = isset($_GET['url']) ? $_GET['url']: "home";
return explode("/", filter_var(trim($url, "/")),FILTER_SANITIZE_URL);
}
}
and main controller
PHP Code:
<?php
/**
* main controller class
*/
class Controller
{
public function view($view,$data = array())
{
extract($data);
// code...
if(file_exists("../private/views/" . $view . ".view.php"))
{
require ("../private/views/". $view . ".view.php");
} else {
require ("../private/views/404.view.php");
}
}
public function load_model($model)
{
if(file_exists("../private/models".ucfirst($model).".php")) {
require("../private/models" .ucfirst($model).".php");
return $model = new $model();
}
return false;
}
}
i am using sublime as my editor
what might be the problem