Daniel Ali
Daniel Ali

Reputation: 23

smarty - error in assign

I use assign like this :

$smarty->assign("akakak", $_POST[do]);

it's work in some cases but it isn't work in some cases

when I add this parameter

$smarty->assign("akakak", $_POST[do], true);

it's always work

Why ?

Upvotes: 0

Views: 478

Answers (2)

rodneyrehm
rodneyrehm

Reputation: 13557

Assigning the values of superglobals ($_GET, $_POST, $_REQUEST, $_SESSION, $_COOKIE, $_SERVER, $_ENV) is redundant. You can access any of these within a template through the {$smarty} variable, in your case {$smarty.post.do}.

The following is true for Smarty3:

The third argument to assign() is the nocache flag. For more information on this, see cacheability of variables. If this actually solved your problem, your real problem lies with your caching. You likely have $smarty->caching = true; set, in which case the template is not rendered on every invocation, but read from cache if possible.

If you need further assistance, you may want to elaborate on the failing cases.

Aside from that, please have a close look at the other comments suggesting $_POST['do'] over $_POST[do] and the use of isset() or empty() where applicable.

Upvotes: 2

Lawrence Cherone
Lawrence Cherone

Reputation: 46602

You should check or set a default value:

<?php 
//Check it or set default for $do
$do=(isset($_POST['do']))?$_POST['do']:'';

//Assign the $smarty var with $do
$smarty->assign("akakak", $do);
?>

Upvotes: 2

Related Questions