Re: [phplib] adding functionality From: Jeff Schmidt (jschmid <email protected>)
Date: 05/08/00

leandro wrote:

> hy all...
> I'm trying to add a stack functionality to phplib..
> so we can track the user throw the site...
> I put aome stuff in page_open().. I think this is write, but I'm not
> sure how to save my new object $stack when I page_close()
>
> anyone ??
>

Hmm, I think for what you want to do, you don't need to modify
page_open(); If you just want to keep an object persistent, for use
throughout the life-time of the user's session, you just need to use the
normal session registering functions from the global scope of your
script.

For objects, this is a little more involved than for other data types,
but here is an example.

Say this is the beginning of your stack object:

class my_stack {

    var $classname = "my_stack"; //this is used as the content for a php
variable-variable that phplib
                                                   // uses to re-create
the object when the person next visit's the page
                                                   // NOTE: this _must_
be the same as the name of your class.

    var $persistent_slots = array("$var1", "$var2"); //This is an array
containing the names of the variables

// in your class that need to be saved and restored

// in order to bring the object back to the same state

// it had during the last page load. Basically, all dynamic

// data in your class.

    function push() {
     . . .
    }

    function pop() {
    . . .
    }

. . . etc . . .
}

Now, as long as you have those variables defined properly in all objects
you want to save (and any objects
that those objects reference, in the case of a tree-or-list like object)
all you have to do from your pages is eg:

page_open(array("sess" => "My_Session", "auth" => "My_Auth"));

if (!isset($stack)) {
   $stack = new my_stack;
   $sess->register("stack");
}

/* your code here */

page_close();

That's it. The next time that user visits a page containing page_open()
{assuming they haven't deleted their session cookie or session get
variable or their session hasn't expired} $stack will be restored from
the point of the page_open() on. If you want that variable/object to
persist with the user beyond any given session you'll want to use the
user object instead of the sess object, but otherwise everything is the
same. E.g:

page_open("sess" => "my_session", "auth" => "my_auth", "user" =>
"my_user");

if (!isset($stack)) {
   $stack = new my_stack;
   $user->register("stack");
}

I hope I've written clearly enough to be understood =)

Have fun,

Jeff Schmidt

P.s. Reading the manual is a good thing, as it explains stuff like this
(although, perhaps, a little more tersely than I have explained it).

--
"Message sent by jschmid <email protected>"

--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-unsubscribe <email protected> For additional commands, e-mail: phplib-help <email protected>