top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

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

+2 votes
155 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 Google+ Share Button LinkedIn Share Button Multiple Social 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
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...