Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

autoload.php

The introduction of spl_autoload_register() gave programmers 
the ability to create an autoload chain, 
a series of functions that can be called to try and load a class or interface. 

For example:

<?php
function autoloadModel($className) {
    $filename = "models/" . $className . ".php";
    if (is_readable($filename)) {
        require $filename;
    }
}

function autoloadController($className) {
    $filename = "controllers/" . $className . ".php";
    if (is_readable($filename)) {
        require $filename;
    }
}

spl_autoload_register("autoloadModel");
spl_autoload_register("autoloadController");
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
7+6 =