1

I'm trying to autoload a class within symfony 2. The class lives in vendor/lessc/lessc.inc.php It's not loading saying the lessc class is not found. What am I doing wrong?

From app/autoloader.php

$loader->registerNamespaces(array( //... 'Less' => __DIR__.'/../vendor/lessc', )); 

From lessc.inc.php

namespace Less; class lessc { //.. } 

From vendor/assetic/src/Assetic/Filter/LessphpFilter.php which calls the lessc class.

namespace Assetic\Filter; use Assetic\Asset\AssetInterface; use Less; //... class LessphpFilter implements FilterInterface { public function filterLoad(AssetInterface $asset) { //... $lc = new Less\lessc(); 

Edit: Solution based on advice I got:

Class path = vendor/Less/lessc.php

vendor/Less/lessc.php

namespace Less; class lessc { 

vendor/assetic/src/Assetic/Filter/LessphpFilter.php is the same as above.

within a twig template

 {% stylesheets '@MyBundle/Resources/public/less/styles.less' filter='lessphp' %} <link rel="stylesheet" href="{{ asset_url }}" /> {% endstylesheets %} 

app/autoloader.php

'Less' => __DIR__.'/../vendor' 

2 Answers 2

2

I think that your class named "lessc" should be in a file named "lessc.php", you should change this line:

'Less' => __DIR__.'/../vendor/lessc' 

for this one:

'Less' => __DIR__.'/../vendor' 

You should change the name of the "lessc" dir for "Lessc". Besides, you should move your assetic filter inside your "Less" namespace.

I hope it helped!

Sign up to request clarification or add additional context in comments.

2 Comments

And if it still doesn't work, you can try use Less\lessc; instead of use Less;
Thanks for the help folks, I put the final solution in the question.
0

Your Name Of Classes is Lessc

If You Root Folder Less:

Add Classes Name In Root Namespace Folder 

Example:

use Less\Lessc; use Less\Lessc as rootClassesOfNamespaces; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.