informatique:php:symfony:gestion_de_la_langue_de_l_utilisateur
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
informatique:php:symfony:gestion_de_la_langue_de_l_utilisateur [09/02/2011 16:06] – créée cyrille | informatique:php:symfony:gestion_de_la_langue_de_l_utilisateur [19/05/2012 00:18] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== | ====== | ||
- | Dans cette page nous allons détecter automatique la langue de l' | + | Dans cette page nous allons détecter automatique la langue de l' |
===== Détection automatique de la langue ===== | ===== Détection automatique de la langue ===== | ||
Ligne 23: | Ligne 23: | ||
==== Le filtre AutoLanguageFilter ==== | ==== Le filtre AutoLanguageFilter ==== | ||
+ | La classe AutoLanguageFilter qui hérite de sfFilter : | ||
<code php> | <code php> | ||
# apps/ | # apps/ | ||
Ligne 30: | Ligne 31: | ||
{ | { | ||
+ | // Est-ce que la culture de l' | ||
if( $this-> | if( $this-> | ||
{ | { | ||
+ | // retrouve les cultures dispo pour le site | ||
$available_cultures = sfConfig:: | $available_cultures = sfConfig:: | ||
- | |||
if( ! is_array($available_cultures) ) | if( ! is_array($available_cultures) ) | ||
{ | { | ||
+ | // Pas trouvées, erreurs de configuration | ||
throw new sfConfigurationException(sprintf(' | throw new sfConfigurationException(sprintf(' | ||
} | } | ||
- | // automatic user's culture selection if not already set | + | |
- | $this-> | + | $this-> |
- | $this-> | + | $this-> |
- | $available_cultures | + | ); |
- | ) | + | // |
- | ); | + | } |
- | // | + | |
- | } | + | |
- | // Execute next filter | + | |
- | $filterChain-> | + | $filterChain-> |
+ | } | ||
+ | } | ||
+ | </ | ||
- | } | + | et activation du filtre: |
+ | # apps/ | ||
+ | ... | ||
+ | # insert your own filters here | ||
+ | AutoLanguageFilter: | ||
+ | class: AutoLanguageFilter | ||
+ | |||
+ | ===== Sélection de la langue par l' | ||
+ | |||
+ | ==== Création IHM de sélection ==== | ||
+ | |||
+ | On va tout d' | ||
+ | |||
+ | <code php> | ||
+ | # apps/ | ||
+ | class defaultComponents extends sfComponents | ||
+ | { | ||
+ | public function executeChangeLanguage(sfWebRequest $request) | ||
+ | { | ||
+ | $available_cultures = sfConfig:: | ||
+ | if( ! is_array($available_cultures) ) | ||
+ | { | ||
+ | throw new sfConfigurationException(sprintf(' | ||
+ | } | ||
+ | |||
+ | $this-> | ||
+ | $this-> | ||
+ | array(' | ||
+ | ); | ||
+ | | ||
} | } | ||
</ | </ | ||
+ | Le template associé à ce composant contient le Form nécessaire à sfFormLanguage: | ||
+ | <code php> | ||
+ | <!-- apps/ | ||
+ | <form action="<? | ||
+ | <label for=" | ||
+ | <?php echo $form[' | ||
+ | <?php echo $form-> | ||
+ | <input type=" | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Ce code (defaultComponents-> | ||
+ | |||
+ | # apps/ | ||
+ | _changeLanguage: | ||
+ | enabled: true | ||
+ | |||
+ | ==== Traitement de la sélection ==== | ||
+ | |||
+ | Création d'une route pour l' | ||
+ | |||
+ | # apps/ | ||
+ | change_language: | ||
+ | url: / | ||
+ | param: { module: default, action: changeLanguage } | ||
+ | |||
+ | Et le code de l' | ||
+ | <code php> | ||
+ | # apps/ | ||
+ | class defaultActions extends sfActions | ||
+ | { | ||
+ | ... | ||
+ | public function executeChangeLanguage($request) | ||
+ | { | ||
+ | $available_cultures = sfConfig:: | ||
+ | if( ! is_array($available_cultures) ) | ||
+ | { | ||
+ | throw new sfConfigurationException(sprintf(' | ||
+ | } | ||
+ | |||
+ | $this-> | ||
+ | $this-> | ||
+ | array(' | ||
+ | ); | ||
+ | |||
+ | if ($this-> | ||
+ | { | ||
+ | // culture has been changed | ||
+ | } | ||
+ | |||
+ | return $this-> | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | Et voilà, j' | ||
informatique/php/symfony/gestion_de_la_langue_de_l_utilisateur.1297263994.txt.gz · Dernière modification : 19/05/2012 00:15 (modification externe)