View previous topic :: View next topic |
Author |
Message |
cptnemo Smarty Rookie
Joined: 09 Sep 2003 Posts: 24
|
Posted: Thu Sep 18, 2003 9:13 pm Post subject: Smarty and PHP Sessions |
|
|
Hey y'all...
Suppose, I have a very big Object(). I want to do all kind of things with it, without rebuilding the entire Object, so I store it in $_SESSION.
And then:
Quote: | if( $session->isRegistered($this->varName) ) {
$this = $session->returnVar( $this->varName );
} |
I test whether the Object exists in $_SESSION, and if so, I replace $this with the $_SESSION Object. So far, so good. The original Object displays results, exactly like I want them.
But when I try a ->display, I get this error:
Quote: | Fatal error: Call to undefined function: smarty_function_assign() in /usr/some/dir/templates_c/%%-24/%%-242218772/template.tpl.php on line 30
|
My $_SESSION Object and 'regular' Object are exactly the same (===), as is the rest of the environment variables. However, something goes wrong. I already wiped all templates_c files and all, but my script keeps on failing on this error.... Any idea? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Sep 18, 2003 9:20 pm Post subject: |
|
|
you mean you register an instance of class Smarty?
no, that won't work. smarty saves it's internal state (about what it loaded and what not) in member variables. this cannot be freezed and thawed easily. |
|
Back to top |
|
cptnemo Smarty Rookie
Joined: 09 Sep 2003 Posts: 24
|
Posted: Thu Sep 18, 2003 9:23 pm Post subject: |
|
|
Aaaargh!!
Well, actually it's an Object, in which a lot of objects are defined, among others an Object that extends Smarty..
But, this basically renders Smarty unusable for advanced coding... Serializing won't work either, I gues... |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Sep 18, 2003 9:26 pm Post subject: |
|
|
you mean not being serializable makes smarty unusable for advanced coding?
if so then "yes".
[EDIT: had to add a smiley - i presume to do advanced coding here and there and i use smarty happily ) |
|
Back to top |
|
cptnemo Smarty Rookie
Joined: 09 Sep 2003 Posts: 24
|
Posted: Thu Sep 18, 2003 9:38 pm Post subject: |
|
|
I didn't want to offend anyone.
But, say, one has an Object as big as this: http://www.superinfinite.com/meuk/all.html
It would be very convenient to store it in some way, instead of rebuilding it every time... Smarty makes that impossible, unfortunately... |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Sep 18, 2003 9:50 pm Post subject: |
|
|
i don't feel offended. if you do serializing/unserializing you shouldn't extend class Smarty but use smarty as a member-variable that is excepted in the return of __sleep() and that is re-referenced in __wakeup(). sorry that the docs don't contain that. |
|
Back to top |
|
cptnemo Smarty Rookie
Joined: 09 Sep 2003 Posts: 24
|
Posted: Thu Sep 18, 2003 9:54 pm Post subject: |
|
|
I'd love to see this working the way I outlined above in an upcoming version... It'll save a lot of users a lot of work... I now have to do a serialize, manage my Smarty object with __sleep and __wakup, and an unserialize..... Oh well, back to the coffee machine, I guess . Anyhow, thanks for the hints. |
|
Back to top |
|
cptnemo Smarty Rookie
Joined: 09 Sep 2003 Posts: 24
|
Posted: Fri Sep 19, 2003 2:32 pm Post subject: |
|
|
After a lot of experimenting and bugfixing, I have the following situation.
An Object, which houses a ContentHandler, which houses a Smarty object ($Object->ContentHandler->Smarty). If I serialize the Object, store it in a $_SESSION, and afterwards grab it from $_SESSION and unserialize it, Smarty still works...
So, no need for the __sleep() and __wakeup(), as said by messju! |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Sep 19, 2003 8:01 pm Post subject: |
|
|
Uhm, what is the advantadge of serializing Smarty? It is not used to store data, nor does it do state transitions (all it requires is an init and after that, it may as well be a static class). Further, if you are serializing Smarty into session, that means you are doing it for EVERY user which is complete overkill since there is more than likely only one setup state for every user anyways. That means that not only are you wasting disk space, but you are burning ram, IO, and processor.
Much better to just instantiate your custom Smarty class, IMHO and not go through the headaches.
I think of Smarty more as a service in this regard and so it is not the type of thing to push into your session. On the other hand, once SRM is viable, it is the type of thing that you might want to consider using, if you ask me.
Please, correct me if I got it wrong! |
|
Back to top |
|
|