Search the Community
Showing results for tags 'spl'.
-
I have : session_start(); spl_autoload_register(null, false); spl_autoload_extensions(".class.php"); function classLoader($class){ $filename = strtolower($class) .'.class.php'; $file = 'core/classes/' .$filename; if(!file_exists($file)){ return false; } require $file; } function connectLoader($connect){ $filename = strtolower($connect) .'.class.php'; $file = 'core/connect/' .$filename; if(!file_exists($file)){ return false; } require $file; } spl_autoload_register('connectLoader'); spl_autoload_register('classLoader'); In an init.php that is called at the top of each page. I keep receiving errors with regards to non member objects when trying to access the site. Fatal error: Call to a member function prepare() on a non-object in /home/a6696695/public_html/core/classes/users.class.php on line 185 on that line is a function that retrieves user data from the database: //function to return the user data public function userData($id){ $query = $this->db->prepare("SELECT * FROM users WHERE id =?"); $query->bindValue(1, $id); try{ $query->execute(); //returns all user data in the form of an array - access in other pages, index etc. return $query->fetch(); }catch(PDOException $e){ die($e->getMessage); } }//end userData function This function is called in the init after the spl calls. //instantiating the classes $users = new Users($db); $admin = new Admin($db); $general = new General(); $helper = new Helper(); //check if user is logged in, get id from session and data if($general->loggedIn() === true){ $userId = $_SESSION['id']; $user = $users->userData($userId); } Help please