我找到this tutorial用于 ZendFramework 1 。我下载较少,并将其放在 project / vendor / 下。
Leafo
└── Less
├── Lessc.php
└── Lessify.php
在 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());
}
不幸的是,我收到了以下错误
致命错误:第53行的/Users/jslim/public_html/littlepinktree/module/Application/Module.php中找不到“Leafo \ Less \ Lessc”类
我在这里有几个问题:
答案 0 :(得分:2)
我通过将整个导演放在 ./ module / Application / src / Less
中解决了这个问题注意:我使用了原始结构,如下所示
src
├── Application
│ └── Controller
│ └── IndexController.php
└── Less
├── LICENSE
├── Makefile
├── README.md
├── composer.json
├── docs
│ └── docs.md
├── lessc.inc.php
├── lessify
├── lessify.inc.php
├── package.sh
├── plessc
└── tests
├── ApiTest.php
├── InputTest.php
├── README.md
├── bootstrap.sh
├── inputs
├── outputs
└── sort.php
在应用程序模块中使用类映射 ./ module / Application / Module.php
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
然后生成 autoload_classmap.php
<?php
// Generated by ZF2's ./bin/classmap_generator.php
return array(
'Application\Module' => __DIR__ . '/Module.php',
'Application\Controller\IndexController' => __DIR__ . '/src/Application/Controller/IndexController.php',
'lessc' => __DIR__ . '/src/Less/lessc.inc.php',
'lessc_parser' => __DIR__ . '/src/Less/lessc.inc.php',
'lessc_formatter_classic' => __DIR__ . '/src/Less/lessc.inc.php',
'lessc_formatter_compressed' => __DIR__ . '/src/Less/lessc.inc.php',
'lessc_formatter_lessjs' => __DIR__ . '/src/Less/lessc.inc.php',
'easyparse' => __DIR__ . '/src/Less/lessify.inc.php',
'tagparse' => __DIR__ . '/src/Less/lessify.inc.php',
'nodecounter' => __DIR__ . '/src/Less/lessify.inc.php',
'lessify' => __DIR__ . '/src/Less/lessify.inc.php',
'ApiTest' => __DIR__ . '/src/Less/tests/ApiTest.php',
'InputTest' => __DIR__ . '/src/Less/tests/InputTest.php',
'lesscNormalized' => __DIR__ . '/src/Less/tests/sort.php',
'SortingFormatter' => __DIR__ . '/src/Less/tests/sort.php',
);
最后,我可以使用它
public function compileLess()
{
if (APPLICATION_ENV == 'production') {
return;
}
$less_file = PROJECT_PATH . '/public/less/style.less';
$css_file = PROJECT_PATH . '/public/css/style.css';
$lessc = new \lessc($less_file);
file_put_contents($css_file, $lessc->parse());
}
答案 1 :(得分:0)
您需要在自动加载器中注册Leafo
命名空间。假设你有这棵树:
MyProject
└── vendor
Leafo
└── Less
├── Lessc.php
└── Lessify.php
你必须像这样注册命名空间:
Zend\Loader\AutoloaderFactory::factory(array(
'Zend\Loader\StandardAutoloader' => array(
'autoregister_zf' => true,
'namespaces' => array(
'Leafo' => '/MyProject/vendor/Leafo',
),
)
));
如果您使用ZendSkeletonApplication,可以在init_autoloader.php
文件中更改此内容。