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

how to show the contents of a session?

 
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 -> General
View previous topic :: View next topic  
Author Message
terra
Smarty Rookie


Joined: 27 Jul 2011
Posts: 26

PostPosted: Thu Mar 14, 2013 6:26 pm    Post subject: how to show the contents of a session? Reply with quote

Hi

how to show the contents of a session? I have the $ _SESSION [alert], how to show the content in the tpl file?


Thanks
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Mar 14, 2013 7:52 pm    Post subject: Reply with quote

http://www.smarty.net/docs/en/language.variables.smarty.tpl
Back to top
View user's profile Send private message Visit poster's website
terra
Smarty Rookie


Joined: 27 Jul 2011
Posts: 26

PostPosted: Thu Mar 14, 2013 8:05 pm    Post subject: Reply with quote

Hi,

thanks.

{$smarty.session.minhalista}


show only

Array

why?

I want to show what is in $ _SESSIO [minhalista]

Quote:
echo "id". $ row ['business_id']. "|". "name". $ row ['BUSINESS_NAME']. "<a href = '#' class = 'del' rel = '". $ id."' nm = '". $ name."'> dEL FAVORITES </ a> <br /> ";


in php show,

Quote:
id: 564 | nome: vende-se celta muito barato. preço de oportunidade. confira DEL FAVORITOS
id: 566 | nome: Palio 2009/2010 DEL FAVORITOS
id: 565 | nome: Celta vermelho, 2 portas, usado. DEL FAVORITOS
id: 568 | nome: Celta vermelho, 2 portas, usado. DEL FAVORITOS
id: 567 | nome: vende-se celta muito barato. preço de oportunidade. confira DEL FAVORITOS


in tpl not



Thanks for help[/quote]
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Mar 14, 2013 8:23 pm    Post subject: Reply with quote

It must be an array of values?

{$smarty.session.minhalista.0}

will show the first one. Or you can loop with foreach.
Back to top
View user's profile Send private message Visit poster's website
terra
Smarty Rookie


Joined: 27 Jul 2011
Posts: 26

PostPosted: Thu Mar 14, 2013 8:33 pm    Post subject: Reply with quote

Hi,

thanks

show me an example, please, have tried everything and nothing works.


Thanks again
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Mar 14, 2013 8:38 pm    Post subject: Reply with quote

Code:
{foreach $smarty.session.minhalista as $s}
  {$s}
{/foreach}


(this is Smarty 3 syntax)
Back to top
View user's profile Send private message Visit poster's website
terra
Smarty Rookie


Joined: 27 Jul 2011
Posts: 26

PostPosted: Thu Mar 14, 2013 8:52 pm    Post subject: Reply with quote

Thanks.


with this example gives error in the TPL


what might be happening? I really need it.

see

in php

Quote:
if ($_SESSION && $_SESSION['minhalista'] != null){
foreach($_SESSION['minhalista'] as $key => $value)
{
$id = $_SESSION['minhalista'][$key];
$sel = mysql_query("SELECT * FROM classificados WHERE business_id = '".$id."'");

while($row = mysql_fetch_array($sel)){


echo "id: ".$row['business_id']." | "."nome: ".$row['business_name']." <a href='#' class='del' rel='".$id."' nm='".$nome."'>DEL FAVORITOS</a><br /> ";
}
}
}


in TPL

Quote:
{foreach $smarty.session.minhalista as $s}
{$s}
{/foreach}
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Mar 14, 2013 8:58 pm    Post subject: Reply with quote

You are selecting data from the database inside the loop. You don't want to do that in Smarty, do that in PHP.

In php in the while loop, instead of echoing push the contents to an array, then assign the array to smarty and loop over the array in the template.

Something like:

PHP:

Code:
while($row = mysql_fetch_array($sel)){
  $rows[] = $row;
}
$smarty->assign('rows',$rows);


Smarty:

Code:
{foreach $rows as $row}
  {$row.id} | {$row.business_name} (etc)
{/foreach}
Back to top
View user's profile Send private message Visit poster's website
terra
Smarty Rookie


Joined: 27 Jul 2011
Posts: 26

PostPosted: Fri Mar 15, 2013 2:12 am    Post subject: Reply with quote

hi.


worked!! thank you very much
Back to top
View user's profile Send private message
terra
Smarty Rookie


Joined: 27 Jul 2011
Posts: 26

PostPosted: Fri Mar 15, 2013 6:55 pm    Post subject: Reply with quote

Hi,

how do I call the TPL file?


if( isset( $_SESSION["minhalista"][$id]) == $id ){


Thanks
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 -> General 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