Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smarty - Getting Posted / Session Variables

Tags:

php

smarty

I'm working on an "In My Basket" Feature on a shopping site. I'm pairing it on productid. I've done a tamper data on the post when you add to basket. The variable that is getting posted is productid.

I've been using This as a guide to output the productid variable. But I'm just not getting a response from the page at all.

The code I am using is {$smarty.request.productid}

The TPL file I am using is HERE I am working on the < div class="inbasket"> which is line 69.

It seems to output with the SERVER_NAME example. But I need that equivalent PHP $_POST VAR.

Does anyone have any idea on what I need to do to pull through the productid and show it on screen, Then I can do an IF statement based on that.

Also worth noting I am using Version 2.6.20 of Smarty

Hoping someone can help me out with this. It appears that smarty is just not showing the session variables at all...

like image 767
StuBlackett Avatar asked Aug 31 '11 08:08

StuBlackett


2 Answers

Using {$smarty.request.productid} will only get values that were are in the $_POST array or the $_GET array. For session vars you would simply use "session" as in {$smarty.session.productid}. With smarty the same applies to

  • $_POST -- {$smarty.post.productid}
  • $_GET -- {$smarty.get.productid}
  • $_REQUEST -- {$smarty.request.productid} (request will get vars from both $_POST and $_GET)
  • $_SESSION -- {$smarty.session.productid}

Put this at the top of your tpl file and it will popup with all assigned smarty vars

{debug}

Want to see what is in the session? Put this at the top of you tpl file

{php}
print_r($_SESSION);
{/php}
like image 51
tom Avatar answered Sep 17 '22 22:09

tom


If you fail to debug, You've another alternative to do.

In PHP file,

$smarty->assign('request_var',$_REQUEST['var1']);

In Smarty TPL,

Use {$request_var}

like image 37
Ankit Avatar answered Sep 20 '22 22:09

Ankit