Trouble Including A Library

I’m trying to include a JSON schema validator library but I’m having trouble getting it to work. The library is called Brainly, and you can find it here (first post, so I can’t embed links): github DOT com SLASH brainly SLASH jvalidator

I added it by putting the Brainly folder under protected/vendor. Then I added the name Brainly into my main.php, under the import section as so:




    'import' => array(

        'application.models.*',

        'application.components.*',

        'application.modules.auth.components.*',

        'application.modules.auth.models.*',

        'application.vendor.*',

        'Money',

        'Brainly',

        'ext.yii-mail.YiiMailMessage'

    ),



And in my code I tried using it in these two ways:


$validator = new \Brainly\JValidator\Validator();


$validator = new Validator();

Unfortunately it still isn’t working well. I get a 500 server error returned with nothing being displayed, and the error is actually logged in the Apache error.log file, with the following message:


PHP Fatal error:  Class 'Brainly\\JValidator\\Validator' not found in /var/www/protected/modules/api/components/APIHelper.php on line 155

I also took a look at the Extending Yii page which tells me to put it under a folder called vendors (notice the ‘s’ at the end, compared to the one I have which was created by the framework). I tried those steps as well and they didn’t work either.

Anyone have any ideas on what I might be doing wrong?

Solved the issue!

For anyone that’s wondering, there’s two changes I needed to make:

[list=1]

[*]I had to also add


Yii::setPathOfAlias('Brainly', dirname(__FILE__).'/../vendor/Brainly');

at the top of my main.php in addition to adding it to the import section.

[*]When calling the actual function, I used this call:


$validator = new Brainly\JValidator\Validator();

[/list]