kyberfabrikken wrote:
Because of PHP's stateless nature, you can't use continuations, which - if I'm not mistaken - is the way Seaside works? A continuation is even more powerful way of preserving state than the way application servers such as JSP or .NET does it. With a continuation, you not only preserve data, but also the program pointer/stack frame. Smalltalk can be a bit alien to developers, who primarily work with C-like languages. For an idea about, what a continuation is, have a look at cocoon:
http://cocoon.apache.org/2.1/userdocs/f ... tions.html
Yes that is correct. PHP does not support this but Seaside offers a lot of very powerful concepts not just continuations.
The two questions people appear to be floating around are programatic HTML generation and callbacks. I would like to address both those things and briefly cover how they are implemented in Phaux.
Have a look at
WHCounter's renderContentOn method. All components that want to render something to a users web-browser must implement renderContentOn. renderContentOn gets passed one argument, an instance of
WHHtmlCanvas. WHHtmlCanvas's job is to return instances of subclasses of
WHTag. Phaux expects renderContentOn to return the product of using WHHtmlCanvas and it's tags which is actually a sting of HTML. WHTag impliments __toString to return exactly what you would expect (an HTML tag). It would not be difficult to swap out Phaux's rendering system for another, in fact using different rendering systems interchangeably would be possible as well.
Rendering HTML programatically encourages the programmer to utilize the language concepts in describing the output. In Phaux you would not describe the entire output of a component in one method you would split up the output across multiple methods. Doing so greatly increases reusability, making it easy to subclass and only change the behavior that you want to with out reconstructing the entire view. A good example of this is
WHNavigation and
WHLiveNavigation. WHNavigation renders a tab based, notebook style navigation component. WHLiveNavigation makes WHNavigation use AJAX to chage it's content area. WHLiveNavigation only redefined the methods it needed to. Flexibility like this is exceptionality difficult with templates.
Back to WHCounter.
Code: Select all
$html->anchor()->callback($this,"add")->with("++")
The above creates an anchor tag, assigned the callback $this->add() to it, and gives it a label ("++"). When a user clicks on the link the method add() of $this will be run.
$this does not need to be $this. It could be your model object on any other object that you might want to operate on.
Code: Select all
public function add(){
$this->counter++;
}
Bacause Phaux is completely stateful the above code works as expected. No need to store the value of $this->counter in a database, file, or the POST/GET vars. The object and everything it references persists in the users session.
Phaux keeps a reference to the callback object and the name of the method to be run when that callback is called in the users session. One of the things that surprised me about PHP was the speed in which it handles session serialization and deserialization. Large applications would most likely want to use tempfs or some other means of session cache.
I hope the above begins to answer some of your questions. Happy hacking
