0

在 fatfree 框架中,我正在尝试编写一个函数,它可以输出缩小的 css/js 并从模板 htm 中调用它。但似乎一旦我尝试使用 htm 调用该函数,整个页面就会呈现为文本,包括 doctype 和所有标签。

我的控制器只有:

public function index($f3, $params) {
            echo \Template::instance()->render($this->BM->themeAbsPath('user_group.htm'));
    }

在 .htm 模板中,我有:

<style>
{{ @BM->minify('css','css/',array(
                                    'bootstrap-theme.min.css',
                                    'main.css',
                                    'vendor/smartmenus-0.9.5/addons/bootstrap/jquery.smartmenus.bootstrap.css',
                                    'vendor/datatables/css/jquery.dataTables.css',
                                    'vendor/datatables/css/jquery.dataTables_themeroller.css'
                                )) }}
</style>

最后是函数:

public function minify($type='css',$folderpath='css/',$files=array()){
        $filepaths = implode(",",$files);
        $this->f3->set('UI',$this->themeRelFolder().'/'.$folderpath); 
        $this->f3->set('minified_'.$type,\Web::instance()->minify($filepaths));
            return $this->f3->get('minified_'.$type);
    }

我没有收到任何 500 错误或类似的错误,那我做错了什么?

4

1 回答 1

0

默认情况下,该Web->minify函数发送一个 Content-Type HTTP 标头。为了防止这种行为,您应该将第三个参数设置为 FALSE:

\Web::instance()->minify($filepaths,NULL,FALSE)

注意:完整的函数签名是:

minify ( string|array $files [, string $mime = NULL [, bool $header = TRUE ]] )
于 2014-03-14T16:54:29.643 回答