0

I have this code:

$fm = $app['assetic.filter_manager'];
$app['assetic.filter_manager'] = $app->share(
    $app->extend('assetic.filter_manager', function($fm, $app) {
        $fm->set('yui_css', new Assetic\Filter\Yui\CssCompressorFilter(
            '/usr/share/yui-compressor/yui-compressor.jar'
        ));
        $fm->set('yui_js', new Assetic\Filter\Yui\JsCompressorFilter(
            '/usr/share/yui-compressor/yui-compressor.jar'
        ));

        return $fm;
    })
);

$app['assetic.asset_manager'] = $app->share(
    $app->extend('assetic.asset_manager', function($am, $app) {
        $am->set('styles', new Assetic\Asset\AssetCache(
            new Assetic\Asset\GlobAsset(
                __DIR__ . '/assetic/resources/css/*.css',
//this below is the line 50.
                array($fm->get('yui_css'))
            ),
            new Assetic\Cache\FilesystemCache(__DIR__ . '/assetic/cache')
        ));
        $am->get('styles')->setTargetPath('css/styles');

        return $am;
    })
);

I'm getting this error:

PHP Notice:  Undefined variable: fm in index.php on line 50

If I have defined the variable $fm, why am I getting this error?

4

2 回答 2

3

尝试这个:

$app->extend('assetic.asset_manager', function($am, $app) use ($fm) {
于 2013-04-26T23:09:39.183 回答
3

如果该顺序正确,您将声明它并将其设置为未定义的值($app['assetic.filter_manager']直到下一行才设置)。

分配后设置 $fm 。

$app['assetic.filter_manager'] = $app->share(
    $app->extend('assetic.filter_manager', function($fm, $app) {
        $fm->set('yui_css', new Assetic\Filter\Yui\CssCompressorFilter(
            '/usr/share/yui-compressor/yui-compressor.jar'
        ));
        $fm->set('yui_js', new Assetic\Filter\Yui\JsCompressorFilter(
            '/usr/share/yui-compressor/yui-compressor.jar'
        ));

        return $fm;
    })
);

$fm = $app['assetic.filter_manager'];
于 2013-04-26T23:10:49.527 回答