Search code examples
phplaravelautoloader

External class not loading in Laravel


Just getting started with Laravel and struggling a bit with the learning curve and lack of detailed documentation. I am trying to use class.upload.php by verot.net and cannot seem to get the class to load.

I uploaded the class directory to application/libraries/class.upload_0.31 and the filename for the actual class is class.upload.php. I then updated the Autoloader::map like so -

Autoloader::map(array(
    'Base_Controller' => path('app').'controllers/base.php',
    'Upload' => path('app').'libraries/class.upload_0.31/class.upload.php',
));

I then attempt to call the class with $handle = new upload(..); as per the documentation for Class Upload.

I believe I followed the documentation correctly to map a class to its location but I keep running into the error Class 'upload' not found. The class name in class.upload.php is upload.

What am I missing?


Solution

  • The class name is upload, with a lowercase u. The array key has to exactly match the class name:

    Autoloader::map(array(
        'Base_Controller' => path('app').'controllers/base.php',
        'upload' => path('app').'libraries/class.upload_0.31/class.upload.php'
      // ^ this should be lowercase
    ));