Zend Framework style autoloader


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.