I was looking at autoloading whilst working with namespaces and I was wondering if anyone could help to fix my autoloader. The code that I had seen was:
<?php
function autoload($className)
{
$className = ltrim($className, "\ ");
$fileName = '';
$namespace = '';
if ($lastNsPos = strripos($className, '\ ')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace("\ ", DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
require $fileName;
}
But it never finds the code, my directory structure is:
src
|
|
application - library
|
|
controller - model - view