php - Spl_autoload_register file not found -


i trying autoload classes spl_autoload register not finding file , getting file not found error.

my file structure:

index.php system/     configs/       config.php     messages/       message.php     user/       user.php 

so here doing.

config.php

i got below function answer

spl_autoload_register(function ($classname) {  # concatenate directly $file variable below # easy viewing on stack overflow)     $ds = directory_separator;     $dir = __dir__;  // replace namespace separator directory separator (prolly not required)     $classname = str_replace('\\', $ds, $classname);  // full name of file containing required class     $file = "{$dir}{$ds}{$classname}.php";     require_once $file; });  use system\user\user;  $obj = new user(); 

user.php

namespace system\user; class user{    ... } 

i getting below error:

fatal error: require_once(): failed opening required 'c:\xampp\htdocs\system\configs\system\user\user.php' (include_path='.;c:\xampp\php\pear') in  

any help?

replace

$file = "{$dir}{$ds}{$classname}.php"; 

with

$file = "{$dir}/../../{$ds}{$classname}.php"; 

so root dir system/ instead of system/configs/


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -