[pmwiki-users] $FmtPV

Peter Bowers pbowers at pobox.com
Sun Feb 6 21:23:37 CST 2011


On Sun, Feb 6, 2011 at 11:44 PM, Thomas Lundgren <publik at lundgren.nu> wrote:
> But - now I want to use that string as a PageVariabel to be displayed on any
> page in my wiki until it is changed by a call to the same function and
> replaced with the new text in the form field. Just to be clear - the text
> should be user uniq. I´m not trying to do anything between different users.

*If* I'm understanding your requirements correctly the problem is that
PVs do not hold their value between successive page-loads.

If I set {$MyVariable} and then load another page I do *not* have
{$MyVariable}.  PVs (in fact, anything that is held just in memory)
are lost at the end of each page-load and you start again from a blank
slate at the load of the next page.

The only way to keep a value from one page to another is something like this:
* Save it in a PTV (PageTextVariable) on a page like the profile
* Save it in a cookie or the session

I would recommend saving to the session -- something like this:

===(snip mycookbook.php)===
if ($_SESSION['myvariable'])
   $FmtPV['$MyVariable'] = $_SESSION['myvariable'];

Markup(...)
function MyFunction(...)
{
   global $FmtPV; //$_SESSION not needed because it is a super-global
   ...
   $_SESSION['myvariable'] = $FmtPV['$MyVariable'] = $RtnVal;
   return $RtnVal;
}
===(snip end)===

Since values in $_SESSION do remain between page-loads you
automatically load $FmtPV from $_SESSION every time you
include_once(mycookbook.php).  Then if the value changes by the markup
you make sure that in addition to setting $FmtPV you also set
$_SESSION.

There's some other stuff you have to do in terms of start_session() or
something like that -- I don't remember what the rules are for when
that has to be done and etc, but you can probably find it in somebody
else's recipe somewhere...  (HttpVariables might be a good one to look
in because it doesn't have other complicating factors besides set
cookies & session variables IIRC)

-Peter



More information about the pmwiki-users mailing list