top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I load all the classes that are placed in diffrent directories in one PHP file?

+2 votes
609 views
How can I load all the classes that are placed in diffrent directories in one PHP file?
posted May 3, 2014 by Sachin Dahda

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

You can auto-load the classes by Using

spl_autoload_register('autoloader::funtion'); 

Like below

class autoloader 
{
 public static function moduleautoloader($class) 
 { 
   $path = $_SERVER['DOCUMENT_ROOT'] . "/modules/{$class}.php"; 
   if (is_readable($path)) require $path;
 }
 public static function daoautoloader($class) 
 {
   $path = $_SERVER['DOCUMENT_ROOT'] . "/dataobjects/{$class}.php";
   if (is_readable($path)) require $path; 
 }
 public static function includesautoloader($class)
 { 
   $path = $_SERVER['DOCUMENT_ROOT'] . "/includes/{$class}.php";
   if (is_readable($path)) require $path; 
 }
}

spl_autoload_register('autoloader::includesautoloader');                       
spl_autoload_register('autoloader::daoautoloader'); 
spl_autoload_register('autoloader::moduleautoloader');
answer May 5, 2014 by Mohit Sharma
0 votes

You mean to say how can we auto-load our classes..

You can do it with

spl_autoload_register('autoloader::funtion'); 

For better and descriptive understanding i suggest you this link:
http://www.php.net/manual/en/language.oop5.autoload.php

answer May 4, 2014 by Sandeep Bedi
...