Skip to content
Daniel Spors edited this page Nov 11, 2020 · 2 revisions

WDF autoloading follows a simple approach: Classes must be stored in files named <lowercaseclassname>.class.php where <lowercaseclassname> must not be full qualified, but the classname only. Search paths for the autoloader are defined using the classpath_add function and searched in the order they were added.

Let's say you defined some classes in the controller folder and some others in the model folder like this:

// controller/home.class.php
class Home extends HtmlPage { }

// controller/search.class.php
class Search extends HtmlPage { }

// model/usermodel.class.php
class UserModel extends Model { }

// model/accountmodel.class.php
class AccountModel extends Model { }

All you need to do is add the root folder to the classpath:

// inside index.php
classpath_add(__DIR__);

From now on you can use all classes following the naming scheme everywhere.

// again in controller/home.class.php
class Home extends HtmlPage
{
    function VerifyUser($username,$password)
    {
        $user = UserModel::Make()
            ->eq('username',$username)
            ->eq("password",sha1($password))
            ->current();
    }
}
Clone this wiki locally