Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从视图中的资源输出内容?_Php_Symfony - Fatal编程技术网

Php 如何从视图中的资源输出内容?

Php 如何从视图中的资源输出内容?,php,symfony,Php,Symfony,我的Symfony2应用程序在服务器计算机上创建一个HTML文件,然后将该文件发送到wkhtmltopdf以从中生成CSS文件。也可以通过浏览器访问此HTML文件 文件中的CSS/JS路径是使用Symfony资产视图帮助器提供的,如下所示: <link href="<?php echo $view['assets']->getUrl('bundles/mybundle/css/style.css') ?>" type="text/css" rel="stylesheet"

我的Symfony2应用程序在服务器计算机上创建一个HTML文件,然后将该文件发送到wkhtmltopdf以从中生成CSS文件。也可以通过浏览器访问此HTML文件

文件中的CSS/JS路径是使用Symfony资产视图帮助器提供的,如下所示:

<link href="<?php echo $view['assets']->getUrl('bundles/mybundle/css/style.css') ?>" type="text/css" rel="stylesheet" />

我发现的一种解决方法是读取控制器中的文件,然后将内容传递给视图

所以在控制器中你有

    $styleFiles = [
        "bundles/mybundle/css/style.css",
        "bundles/mybundle/css/print.css"
    ];

    $style = "";

    foreach ($styleFiles as $file) {
        $style .= file_get_contents($this->get("kernel")->getRootDir() . "/../web/" . $file);
    }
现在,您只需在视图中为此添加一个输出:

<style type="text/css">
    <?= $style ?>
</style>