I have found this tutorial which is for ZendFramework 1. I download less and put it under project/vendor/.
Leafo
└── Less
├── Lessc.php
└── Lessify.php
In project/module/Application/Module.php
...
public function onBootstrap(MvcEvent $e)
{
...
$this->compileLess();
}
...
public function compileLess()
{
if (APPLICATION_ENV == 'production') {
return;
}
require_once PROJECT_PATH . '/vendor/Leafo/Less/Lessc.php';
$less_file = PROJECT_PATH . '/public/less/style.less';
$css_file = PROJECT_PATH . '/public/css/style.css';
$lessc = new \Leafo\Less\Lessc($less_file);
file_put_contents($css_file, $lessc->parse());
}
Unfortunately, I get the error below
Fatal error: Class 'Leafo\Less\Lessc' not found in /Users/jslim/public_html/littlepinktree/module/Application/Module.php on line 53
I have a few questions here:
- How do I integrate 3rd party library to ZF2 (if the 3rd party library is not using namespace)?
- Is there any example showing how to integrate LESS to ZF2?
You need to register the
Leafo
namespace in the autoloader. Let's say you have this tree:Than you have to register the namespace like this:
If you'r using the ZendSkeletonApplication you can change this in the
init_autoloader.php
file.I have solved this by putting the whole director in ./module/Application/src/Less
NOTE: I used back the original structure as follow
Use class map in Application module ./module/Application/Module.php
Then generate autoload_classmap.php
Finally, I can use it