Autoloader - What am i doing wrong


I'm trying to setup my autoloader, so I can use my validations inside my models. Here is what i've done so far:


$loader->registerNamespaces( array( 'Validation' => 'validation/' ) )->register();

var_dump(new Validation\Validate());

My Validate class is inside app/validation/

Why is it, that it can't find the class??

You have to specify the full path to the directory:

$loader->registerNamespaces( array( 'Validation' => '../app/validation/' ) )->register();


Loader.php is inside app/ directory? Or inside app/config/? if in app/config/:

$loader->registerNamespaces( array( 'Validation' => __DIR__.'/../validation/' ) )->register();

And app/validation/Validate.php file begin:

namespace Validation;

Thanks for the quick anwers!

My loader was inside config, so i got it to work Paulius - Thank Andres, still the same code tho just diffrent folders :-)

In my model i got a function called validation

Is this the best code?

$validation = new \Validation\Validate();

    $messages = $validation->validate($_POST);
    if (count($messages)) {
        foreach ($messages as $message) {
            echo $message, '<br>';


I'm using this.

How would you set your custom rules? That's a lot of code if you want min and max length and so on?


did your project follow PSR-4 convention?