Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35973

CakePHP class custom import

I have a site in cakephp 2.X and I want to load a class (less2c.php) into my controller to use it inside my model. I have put my file lessc.php inside the folder /app/Lib Into my controller I have done this:

App::uses('Less2c', 'Lib');
class WidgetsController extends AppController {

}

And into my Model Widget I have done this:

public function beforeSave(){
    $less = new Less2c();
    try {
     $less->compile("invalid LESS } {");
    } catch (exception $e) {
     return false;
    }

    return true;
}   

But when I try to save return me:

Error: Class 'Less2c' not found 

What I'm wrong?

Thanks

Upvotes: 0

Views: 1101

Answers (1)

liyakat
liyakat

Reputation: 11853

As i guess your class name should be Lessc instead of Less2c so there is one error in including your external lib to load into cakephp model and controlller just try to change with

App::uses('Lessc', 'Lib'); instead of App::uses('Less2c', 'Lib');

Or if you can still not found working then please go throw this cakephp.org Document for loading external library in cakephp 2.X

Upvotes: 1

Related Questions