Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Can't use Asset in advanced mode
  • Hello all!

    I want to make multi-template project and try to use Asset class in advanced mode as separate instances.

    When I try use static class, it works ok:
    - In base controller -
    Asset::add_path('assets/face/');
    Asset::css('style.css', array(), 'face');

    - In view -
    <?=Asset::render('face')?>

    But when I try use instance of class, something goes wrong:
    - In base controller -
    $asset = Asset::forge('face', array('paths' => 'assets/face/'));
    $asset->css('style.css', array(), 'facegrp');

    - In view -
    <?=Asset::instance('face')->render('facegrp')?>

    In the last way I get the error:
    Fuel\Core\FuelException [ Error ]: Could not find asset: style.css

    Can you help me to understand, what do I do wrong?
    Thanks.

    PS: The style file style.css is placed in assets/face/css/.
  • Ok. I decided to approach the issue seriously and installed the netbeans with xdebug :)
    I find out that Asset::forge('face', array('patths' => 'assets/face/')) has no effect I expected. No new path was added. I don't known is it a bug or I don't understand all of the developers plans for this config parameter, but I also find out that $asset->add_path('asset/face/) works good like as Asset::add_path('asset/face/') with static version.

    I am satisfied with that, but maybe Asset::forge has a bug, what do you think about it?
  • HarroHarro
    Accepted Answer
    Asset::forge() does:

    new \Asset_Instance(array_merge(static::$default_config, \Config::get('asset'), $config));

    So it merges the default config, any asset config file loaded, and the config you pass, and passes that on to the instance created.

    The constructor of Asset_Instance does:

    // global search paths
    foreach ($config['paths'] as $path)
    {
        $this->add_path($path);
    }

    So you see that 'paths' is defined as an array, not as a string:

    $asset = Asset::forge('face', array('paths' => array('assets/face/')));
  • Thank you. You are right!
  • Oops. You are right, but not documentation.

    http://fuelphp.com/docs/classes/asset/advanced.html



    Example

    // instantiate a asset object with a custom search path
    $asset = Asset::forge('custom', array('paths' =&gt; 'custom/assets/');

  • The config docs are ok (they specify it has to be an array) but the two examples in advanced are indeed incorrect. I've fixed those.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion