Posted By

kendsnyder on 01/20/11


Tagged

autoload SPL zend


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

asifjavedall


Zend Framework style autoloader


 / Published in: PHP
 

  1. spl_autoload_register('autoloadByUnderscore');
  2.  
  3.  
  4. function autoloadByUnderscore($class) {
  5. $pwd = dirname(__FILE__);
  6. $filename = str_replace('_','/',$class) . '.php';
  7. $path = "$pwd/../lib/$filename";
  8. if (is_file($path)) {
  9. require_once $path;
  10. }
  11. }
  12.  
  13. // or rediculously simple:
  14. function autoloadByUnderscore($c) {
  15. require_once(dirname(__FILE__) . '/../lib/' . str_replace("_", '/', $c) . '.php');
  16. }

Report this snippet  

You need to login to post a comment.