You can use define('ROOT', dirname(__FILE__)); and define('DS', DIRECTORY_SEPARATOR);
Tip
spl_autoload_register() provides a more flexible alternative for
autoloading classes. For this reason, using __autoload() is
discouraged and may be deprecated or removed in the future.
So do code should look like this:
<?php
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__)); //This is full path
spl_autoload_register('Autoloader'); //You can use annonymous function here
function Autoloader($class_name){
$filename = ROOT.DS.strtolower($class_name).".php";
var_dump($filename);
if(file_exists($filename)){
require_once ($filename);
}else{
throw new Exception("Unable to load ".$class_name."in".$filename);
}
}
$card = new Cardclass();
With __autoload:
<?php
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__)); //This is full path
function __autoload($class_name){
$filename = ROOT.DS.strtolower($class_name).".php";
var_dump($filename);
if(strpos($class, 'CI_') !== 0) {
if(file_exists($filename)){
require_once ($filename);
}else{
throw new Exception("Unable to load ".$class_name."in".$filename);
}
}
}
$card = new Cardclass();
echo $filename;and check the output path