gpt4 book ai didi

php - assetic - 无法写入 Assets

转载 作者:可可西里 更新时间:2023-10-31 22:51:28 31 4
gpt4 key购买 nike

这是我的目录结构(这只是一个测试项目):

stan@mypc:/generate_assets$ sudo tree -L 3 -p
.
├── [drwxr-xr-x] assets
│   └── [drwxr-xr-x] css
│   ├── [-rw-r--r--] test1.css
│   └── [-rw-r--r--] test2.css
├── [-rw-r--r--] composer.json
├── [-rw-r--r--] composer.lock
├── [drwxrwxrwx] public
├── [-rwxr-xr-x] run
└── [drwxr-xr-x] vendor
....skipping...

这是我应该生成 Assets 的简单脚本(“运行”文件):

#!/usr/bin/env php

<?php
//loading composer's autoload
chdir(__DIR__);
if (file_exists('vendor/autoload.php')) {
include 'vendor/autoload.php';
}

use Assetic\Asset\AssetCollection;
use Assetic\Factory\AssetFactory;
use Assetic\Asset\FileAsset;
use Assetic\Asset\GlobAsset;
use Assetic\Filter\LessFilter;
use Assetic\Filter\CssMinFilter;
use Assetic\AssetWriter;
use Assetic\AssetManager;

//Asset manager
$am = new AssetManager();

//Add all css files
$css = new GlobAsset('assets/css/*.css', array(new CssMinFilter()));
$am->set('basecss', $css);

// Dumping assets into public
$writer = new AssetWriter('public');
$writer->writeManagerAssets($am);

所以 - 我预计来自 assets/css 的 css 文件将被组合、缩小并转储到名为“basecss.css”的公共(public)目录中。这是我得到的异常:

PHP Fatal error:  Uncaught exception 'RuntimeException' with message 'Unable to write file public/' in /generate_assets/vendor/kriswallsmith/assetic/src/Assetic/AssetWriter.php:106
Stack trace:
#0 /generate_assets/vendor/kriswallsmith/assetic/src/Assetic/AssetWriter.php(65): Assetic\AssetWriter::write('public/', '*{color:green}?...')
#1 /generate_assets/vendor/kriswallsmith/assetic/src/Assetic/AssetWriter.php(54): Assetic\AssetWriter->writeAsset(Object(Assetic\Asset\GlobAsset))
#2 /generate_assets/run(31): Assetic\AssetWriter->writeManagerAssets(Object(Assetic\AssetManager))
#3 {main}
thrown in /generate_assets/vendor/kriswallsmith/assetic/src/Assetic/AssetWriter.php on line 106

所以 - assetic 似乎试图转储名为“public”而不是“public/basecss.css”的文件?有什么帮助吗?

附言决议:

好的。苏。显然我必须跑

$css->setTargetPath('css_file_name.css');   

然后它成功了......

最佳答案

文档中不完全清楚,但在 Dumping Assets to static files 中确实提到了那个部分

$writer->writeManagerAssets($am);

“将使用 Assets 的目标路径。”所以是的,正如您建议的那样,在编写 Assets 之前设置目标路径将解决问题:

$css->setTargetPath('css_file_name.css');   

关于php - assetic - 无法写入 Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14538335/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com