Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

méthode GET et message de "notice"

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: French
View previous topic :: View next topic  
Author Message
manuuk
Smarty n00b


Joined: 17 May 2008
Posts: 2

PostPosted: Sun May 18, 2008 8:35 am    Post subject: méthode GET et message de "notice" Reply with quote

Bonjour,
Je souhaite faire afficher un élément div en fonction d'une part de l'existence ou non d'une variable déclaré dans l'adresse, et si elle existe de sa valeur, pour cela dans mon fichier php j'ai :

Code:

$news=$_GET['news'];
if( !isset($news) ) {
    $news = 'no';
}

$smarty->assign('news', $news);


Et dans le tpl j'ai :

Code:

<style>
{if $news eq 'yes'}
  {literal}
.news {
display: block;
}
  {/literal}
{else}
<!-- news off -->
{/if}
</style>


C'est simplement un display: none - display: block en css.

Mon problème c'est que même si cela fonctionne correctement smarty m'affiche :
Quote:

Notice: Undefined index: news in ...index.php on line 13
(la ligne 13 correspond à celle où $_Get se situe. Je comprend bien que si j'appelle mon site sans passer la variable dans l'adresse (ce qui est le cas quand on tape l'adresse du site sans index.php?news=), elle ne soit pas déclaré à ce moment là, mais je fais un test par la suite ...

J'ai pensé rajouter :
Code:

$smarty->debugging = false;
$smarty->error_reporting  =  null;

juste avant dans mon fichier php, mais ça ne change rien !

Quelqu'un à une idée ?
Back to top
View user's profile Send private message
Vynka
Smarty Rookie


Joined: 30 Apr 2003
Posts: 17
Location: Belgium

PostPosted: Wed May 21, 2008 8:24 am    Post subject: Reply with quote

Salut;

Pourquoi ne pas directement tester ton "GET", dans le PHP, au lieu de l'assigner puis de le tester. (C'est l'assignation qui lance l'erreur)

Code:

$news = ( isset($_GET['news'] )?$_GET['news']:"no";
$smarty->assign('news', $news);


A tester Question ...

++
_________________
Au pays des Gloups!
http://www.wishlist.lu
Back to top
View user's profile Send private message Visit poster's website
manuuk
Smarty n00b


Joined: 17 May 2008
Posts: 2

PostPosted: Wed May 21, 2008 11:00 am    Post subject: ok! Reply with quote

Salut,

Ça marche très bien, il manquait juste une parenthèse dans ton expression Wink

Merci beaucoup.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: French All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP