如何将LESS集成到ZendFramework 2中 [英] How to integrate LESS into ZendFramework 2

查看:75
本文介绍了如何将LESS集成到ZendFramework 2中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现本教程用于 ZendFramework 1 .我下载得较少,并将其放在 project/vendor/下.

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

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

致命错误:在第53行的/Users/jslim/public_html/littlepinktree/module/Application/Module.php中找不到类'Leafo \ Less \ Lessc'

Fatal error: Class 'Leafo\Less\Lessc' not found in /Users/jslim/public_html/littlepinktree/module/Application/Module.php on line 53

我在这里有几个问题:

  1. 如何将第三方库集成到ZF2(如果第三方库未使用命名空间)?
  2. 有没有显示如何将 LESS 集成到ZF2的示例?
  1. How do I integrate 3rd party library to ZF2 (if the 3rd party library is not using namespace)?
  2. Is there any example showing how to integrate LESS to ZF2?

推荐答案

我已通过将整个导演放置在 ./module/Application/src/Less

I have solved this by putting the whole director in ./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());
}

这篇关于如何将LESS集成到ZendFramework 2中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆