On crée ce fichier dans le répertoire lib/ ou a l’endroit ou on veut du moment que l autoloader de sf peut le trouver, perso je l’ai mit dans lib/vendor/hio/
sfStatics.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| <?php
class sfStatics {
static public $statics;
static public $number;
static public $index = 0;
private static $instance = null;
public static function getInstance($statics) {
if(is_null(self::$instance))
self::$instance = new sfStatics($statics);
return self::$instance;
}
public function __construct($statics) {
self::$statics = $statics;
self::$number = sizeof($statics)-1;
}
public function pickOne($n = null) {
if(is_null($n)) {
if(self::$index > self::$number)
self::$index = 0;
$static = self::$statics[self::$index];
self::$index++;
} else {
if(isset(self::$statics[$n])) {
$static = self::$statics[$n];
} else {
$static = self::$statics[0];
}
}
return $static;
}
public function __toString() {
return $this->pickOne();
}
} |
ensuite on crée un helper qui va bien
mkdir /lib/helper a la racine de son projet (là ou se trouve ./symfony)
StaticHelper.php
<?php
function pickOneStatic($n = null) {
$a = sfStatics::getInstance(sfConfig::get('app_static_urls'));
return $a->pickOne($n);
}
on met la liste de ses cdn dans app.yml (apps/frontend/config/app.yml)
# default values
all:
static:
urls: ['http://static1.gik.li', 'http://static2.gik.li', 'http://static3.gik.li', 'http://static4.gik.li']
ensuite on passe au chose serieuse dans ses templates
<link rel="shortcut icon" href="<?php echo pickOneStatic(0)?>/images/favicon.ico" />
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo pickOneStatic(0)?>/css/style.min.css" />
dans ses 2 exemples on voit un 0 en argument (0 = le premier cdn de la liste du app.yml), c’est pour délivrer ce contenu tjs a partir du même cdn par exemple qd vous avez plusieurs fois la même images dans une page ou pour que les fichiers js soit cacher correctement par le navigateur
2 eme exemple:
<?php foreach($images as $image): ?>
<?php if(file_exists(sfConfig::get('sf_web_dir').$image->getPath().sfConfig::get('app_images_thumbs_dir').$image->getName())): ?>
<a href="<?php echo url_for('@show?slug='.$image->getContent()->getSlug()) ?>" title="<?php echo $image->getContent()->getTitle() ?>">
<img src="<strong><?php echo pickOneStatic()?></strong><?php echo $image->getPath().sfConfig::get('app_images_thumbs_dir').$image->getName() ?>" width="60" height="60" alt="<?php echo $image->getName() ?>"/>
</a>
<?php endif ?>
<?php endforeach ?>
donnera
<a href="/gran-turismo-5-suzuka-sous-la-pluie-en-video-la-claque-tout-simplement-1" title="Gran Turismo 5 : Suzuka sous la pluie en vidéo - La claque, tout simplement">
<img src="http://static1.gik.li/img/2010-11-21/thumbs/051cb8a3476f3fe29ee4975ec32d217c72fb7593.jpg" width="60" height="60" alt="051cb8a3476f3fe29ee4975ec32d217c72fb7593.jpg"/>
</a>
<a href="/jolibook-now-on-sale-in-the-uk-first-batch-of-orders-ships-monday" title="Jolibook now on sale in the UK, first batch of orders ships Monday">
<img src="http://static2.gik.li/img/2010-11-21/thumbs/067c639cac46fa7fe93748a9de23504c1ede1701.jpg" width="60" height="60" alt="067c639cac46fa7fe93748a9de23504c1ede1701.jpg"/>
</a>
<a href="/ea-sports-on-nba-elite-it-was-just-going-to-be-a-bad-game-nba-elite" title="EA Sports On NBA Elite: "It Was Just Going To Be A Bad Game" [Nba Elite]">
<img src="http://static3.gik.li/img/2010-11-21/thumbs/524068c6bd9e5f1ffd40311f843cdbac8acfbfb8.jpg" width="60" height="60" alt="524068c6bd9e5f1ffd40311f843cdbac8acfbfb8.jpg"/>
</a>
<a href="/bellemanie-bellemanie-2010-watercolor-ink-drawing" title="bellemanie:
Bellemanie - (2010, Watercolor & ink drawing)">
<img src="http://static4.gik.li/img/2010-11-21/thumbs/58c5c1637ea9f1193fc4415ff3e1dc5e2ac77d40.jpg" width="60" height="60" alt="58c5c1637ea9f1193fc4415ff3e1dc5e2ac77d40.jpg"/>
</a>
<a href="/laterality-in-canine-cradling-madscience" title="Laterality in canine cradling [Madscience]">
<img src="http://static1.gik.li/img/2010-11-21/thumbs/feb4a03be8a2a201eac3cdd0cfe8d6fb5e00e624.jpg" width="60" height="60" alt="feb4a03be8a2a201eac3cdd0cfe8d6fb5e00e624.jpg"/>
</a>
et ainsi de suite a chaque appel de la fonction sans argument ça passera au prochain cdn