或,您可以创建一个名为stylesheets.php的文件并嵌入它:
><style> <?php include('/assets/stylesheets.php'); </style>
>另外,您可以生成.css和.js文件,并且只需将其视为正常情况即可。 您可以为此使用AssetWriter:
use Assetic\AssetWriter; $scripts.js = new AssetCollection(array( new GlobAsset('/assets/js/libs/*'), new FileAsset('/assets/js/app.js'), ), array( new JSMinFilter(), )); // Set target path, relative to the path passed to the // AssetWriter constructor as an argument shortly $scripts->setTargetPath('scripts.js'); $am->set('scripts.js', $scripts.js); // see above for instantiation of $styles $styles->setTargetPath('stylesheets.css'); $am->set('styles', $styles); $writer = new AssetWriter('/assets/build'); $writer->writeManagerAssets($am);
>您可以创建一个命令行脚本以作为工作流程的一部分来执行此操作,或者使用Guard等工具“观察”文件系统并在相关文件之一更改时重新运行它。
缓存>
use Assetic\Asset\AssetCache; use Assetic\Asset\FileAsset; use Assetic\Cache\FilesystemCache; use Assetic\Filter\Yui; $yui = new Yui\JsCompressorFilter('/path/to/yuicompressor.jar'); $js = new AssetCache( new FileAsset('/path/to/some.js', array($yui)), new FilesystemCache('/path/to/cache') ); // the YUI compressor will only run on the first call $js->dump(); $js->dump(); $js->dump();
什么是Assetic,它如何起作用?
我如何在Assetic中使用过滤器?您的资产以各种方式。例如,您可以使用CSS Minification过滤器来减少CSS文件的大小,也可以使用较少的编译过滤器,以将您的文件较少的文件编译到CSS中。要在Assetic中使用过滤器,您需要将其定义在配置中,然后将其应用于您的资产。
>我如何在Assetic中调试资产?可用于对您的资产问题进行故障排除的模式。当启用调试模式时,资产将分别提供每个资产,而不是将它们组合到一个文件中。这可以使您可以更容易地识别和解决您的资产问题。
是的,是的,Assetic是独立的库,可以与任何PHP一起使用应用。虽然通常与Symfony一起使用,但也可以与其他Web应用程序框架一起使用。要与另一个框架一起使用Assetic,您需要使用Composer安装它,然后使用它来管理您的Web资产。
>以上是开始使用资产的详细内容。更多信息请关注PHP中文网其他相关文章!