array_unique und FileAsset

Einklappen
X
 
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge
  • paha77
    Contao-Nutzer
    • 05.02.2014
    • 8

    #1

    array_unique und FileAsset

    Hallo,

    Ich habe ein Problem mit FileAsset:

    Dieser Code funktioniert:

    PHP-Code:
    $asset = new \Assetic\Asset\FileAsset(TL_ROOT . '/assets/style1.css');
    $GLOBALS['TL_CSS'][] = $asset; 
    
    Mit diesem bekomme ich eine Fehlermeldung:

    PHP-Code:
    $asset = new \Assetic\Asset\FileAsset(TL_ROOT . '/assets/style1.css');
    $GLOBALS['TL_CSS'][] = $asset;
    $asset = new \Assetic\Asset\FileAsset(TL_ROOT . '/assets/style2.css');
    $GLOBALS['TL_CSS'][] = $asset; 
    
    Code:
    Recoverable error: Object of class Assetic\Asset\FileAsset could not be converted to string in system/modules/theme-plus/classes/src/ThemePlus/ThemePlus.php on line 791
    Und das Problem liegt in:

    system/modules/theme-plus/classes/src/ThemePlus/ThemePlus.php

    in Programmzeil 791:

    PHP-Code:
                $this->addAssetsToCollectionFromArray(
                    array_unique($GLOBALS['TL_CSS']),
                    'css',
                    true,
                    $collection,
                    $stylesheets,
                    $defaultFilters
                ); 
    
    weil:

    http://de3.php.net/manual/de/function.array-unique.php
    Hinweis: Zwei Elemente werden nur dann als gleich angesehen, wenn (string) $elem1 === (string) $elem2. In Worten: Wenn die String-Repräsentation die gleiche ist. Das erste Element wird verwendet.
    Habt ihr eine Lösung oder ist das ein Bug?

    Danke
  • paha77
    Contao-Nutzer
    • 05.02.2014
    • 8

    #2
    Eine Lösung habe ich gefunden:

    PHP-Code:
                $asset = new \Assetic\Asset\FileAsset(TL_ROOT . '/assets/style1.css');
                $collection = new \Assetic\Asset\AssetCollection(array($asset));
                $asset = new \Assetic\Asset\FileAsset(TL_ROOT . '/assets/style2.css');
                $collection->add($asset);
                $GLOBALS['TL_CSS'][] = $collection; 
    

    Kommentar

    • Flex
      Contao-Urgestein
      • 03.06.2010
      • 2149

      #3
      Wäre das so nicht effektiver?

      PHP-Code:
                  $collection = new \Assetic\Asset\AssetCollection(array(
                      new \Assetic\Asset\FileAsset(TL_ROOT . '/assets/style1.css'),
                      new \Assetic\Asset\FileAsset(TL_ROOT . '/assets/style2.css')
                  )); 
                  $GLOBALS['TL_CSS'][] = $collection; 
      
      Bin mir aber nicht 100%ig sicher ob das so klappt... Aber du machst mit der Zuweisung ja nichts, von daher sollte die nicht nötig sein.

      Kommentar

      Lädt...