ada/zf-assetic

此包已被废弃,不再维护。没有建议的替代包。
最新版本(dev-master)的此包没有可用的许可信息。

dev-master 2013-02-01 20:18 UTC

This package is not auto-updated.

Last update: 2020-12-11 19:24:40 UTC


README

ZfAssetic 是两个 ViewHelper,帮助开发者在 Zend Framework 视图中集成 Assetic

<?php
// In your view...
$this->cssAsset()->captureStart();
?>
<link rel="stylesheet" type="text/css" href="/media/css/styles.css" />
<link rel="stylesheet" type="text/css" href="/media/css/box.css" />
<?php
$this->cssAsset()->captureStart();
echo $this->cssAsset();
// Will output something like this :
// <link rel="stylesheet" type="text/css" href="/asset/0141522526d6be5302041ffa6093933b.css" />
?>

安装

  1. 将 ZfAssetic 目录添加到您的 include_path
  2. 使用兼容 psr-0 的自动加载器。将命名空间 "ZfAssetic" 添加到您的自动加载器
  3. 在您的视图中注册类 ZfAssetic_ViewHelper_CssAsset 和 ZfAssetic_ViewHelper_ScriptAsset。

配置

要使用这些助手,您必须创建一个 Assetic AssetFactory 来管理过滤器。然后可以使用 setAssetFactory() 方法或通过将键 AssetFactory 设置到 Zend_Registry 中直接将工厂添加到助手

<?php
$factory = new Assetic\Factory\AssetFactory('/path/where/files/to/be/filtered/are');

$helper = new ZfAssetic_ViewHelper_CssAsset();

$helper->setAssetFactory($factory);
// Or...
Zend_Registry::set('AssetFactory', $factory);

此外,您还需要设置放置生成的资产的路径以及您的 Web 服务器配置为提供文件的路径

<?php

$helper = new ZfAssetic_ViewHelper_CssAsset();

$public_dir = "/var/www";
$asset_dir = "/var/www/assets";

$helper->setPublicDirectory($public_dir);
$helper->setAssetDirectory($asset_dir);