Voici la portion de code PHP à utiliser pour créer une redirection depuis l'un de vos scripts :
// Récupère l'instance de l'objet application
$app = JFactory::getApplication();
// Déclaration du lien vers lequel rediriger l'utilisateur
$link = 'http://www.neojoomla.com/';
$app->redirect( $link );
Pour aller un peu plus loin, il est également possible d'ajouter un message à votre redirection, précisant généralement le résultat de l'opération qui vient d'être exécutée (exemple : confirmation de l'enregistrement de données, confirmation de l'envoi d'un mail, détection d'une erreur dans les données soumises, échec du traitement, ...) :
// Récupère l'instance de l'objet application
$app = JFactory::getApplication();
// Déclaration du lien vers lequel rediriger l'utilisateur
$link = 'http://www.neojoomla.com/';
// Définition du message à afficher (optionnel)
$msg = 'Vos données ont été enregistrées avec succès.';
$app->redirect( $link, $msg );
Enfin, vous pouvez aussi définir un type de message, pour adapter sa mise en forme. Par défaut, le message sera de type "message", mais vous pouvez également utiliser les types "notice" et "error" pour un avertissement ou un message d'erreur.
Voici un exemple complet :
// Récupère l'instance de l'objet application
$app = JFactory::getApplication();
// Déclaration du lien vers lequel rediriger l'utilisateur
$link = 'http://www.neojoomla.com/';
// Définition du message à afficher (optionnel)
$msg = 'Vos données ont été enregistrées avec succès.';
$app->redirect( $link, $msg, $msgType='message' );
La position du message ainsi que sa mise en forme sont définies dans le template de Joomla. Le plus souvent, le message apparaît en haut de page, juste en-dessous du menu-principal, mais il est tout à fait possible de le déplacer et de personnaliser son apparence également, nous y reviendrons prochainement.
|