Page 2 of 3
Re: Postback Implementation
Posted: Fri Oct 23, 2009 10:46 am
by JNettles
.NET does postbacks by copious amounts of Javascript and hidden fields. Declare an asp form once on the page, .NET injects several hidden fields when the page is rendered to remember the viewstate. The form is posted, the javascript handles the postback and repopulates the fields. Prado works in much the same way, if I remember correctly, though I could be mistaken as I haven't spent much time in that part of the engine.
I love the power that Prado brings to the table in terms of its similarities with .NET and the unique MVC architecture that it uses (which is a markedly different approach than what most PHP frameworks use) but in my opinion Prado has grown far too fat and obtuse. I love the concept - in my mind it makes the best approach to code readability - completely separate markup and code, and code is blocked off into events. I wrestle with the evils of procedural programming every day that I work in PHP - yes, I know that it is technically an "object-oriented" language but in reality your scripts execute top to bottom and you can simply inject instances of objects along the way.
For example, look at this markup from PRADO.
Code: Select all
<com:TButton ID="Button1" Text="Click!" OnClick="sayHello" />
....and then into our code-behind....
Code: Select all
<?php
class Home extends TPage
{
public function sayHello($sender, $param)
{
$sender->Text="Yello!";
}
}
How's this for separation of markup and logic? Prado has created a situation where markup is markup and that's it! I do quite a bit of work creating Joomla components and their documentation is constantly crowing about their MVC pattern separating the code from the presentation but by the end of the day my presentation file is littered with PHP control structure snippets hiding blocks of HTML or injecting variables. This, to me, is all very pointless.
Having your markup represented as accessible objects in your code-behind is the perfect situation for me. This way I can actually separate my code from my markup and if I need to change something I can simply access the object, modify a property, and be done. .NET does this nearly flawlessly and Prado's made a fine effort at duplicating it, but the model has grown a bit to complex for my tastes, hence, my own framework which takes the best of Prado and leaves out the unneeded fat.
Re: Postback Implementation
Posted: Fri Oct 23, 2009 5:16 pm
by Christopher
I am guessing that this is mostly used for forms managers? It seems like you want something that parses a template and produces HTML/Javascript that works with code you write using the the form manager?
Re: Postback Implementation
Posted: Sat Oct 24, 2009 2:45 pm
by JNettles
Postback is largely for the forms management yes but the engine is not specific to forms. I use it to build just about any web site.
Re: Postback Implementation
Posted: Sat Oct 24, 2009 5:23 pm
by Christopher
I can see how it might be a style that some like for forms. I am not sure how well it compares to PHP templates with helpers? This .Net style seems a little old school in PHP. But maybe if you showed more clearly how you are translating the ideas into PHP the advantages would be clearer.
Re: Postback Implementation
Posted: Mon Oct 26, 2009 7:06 am
by josh
http://www.zend.com/en/webinar/Framewor ... 081015.flv
Login required. I think this is the behavior you are looking for.
To bring everyone else on the same page he basically wants a "remote object" he can call methods on. I think postback is not the right term here.
Re: Postback Implementation
Posted: Mon Oct 26, 2009 10:33 am
by Jenk
Callback. As I posted before.

Re: Postback Implementation
Posted: Mon Oct 26, 2009 2:28 pm
by Christopher
josh wrote:To bring everyone else on the same page he basically wants a "remote object" he can call methods on. I think postback is not the right term here.
Aren't there are number of PHP/Ajax libraries that allow you to do that? I think the difference here is that there is a template library that creates the Javascript for you.
Re: Postback Implementation
Posted: Mon Oct 26, 2009 2:57 pm
by josh
The video I linked shows one
Re: Postback Implementation
Posted: Mon Oct 26, 2009 3:37 pm
by JNettles
My ultimate goal with this is absolute separation of code and markup. You shouldn't have PHP mixed in with your markup - ever. Its getting there, but not quite - I'm not as savvy at DOM parsing as I wish I was.
Re: Postback Implementation
Posted: Mon Oct 26, 2009 3:39 pm
by John Cartwright
JNettles wrote:You shouldn't have PHP mixed in with your markup - ever
I would completely disagree with this, however, I won't go there in light of derailing this thread

Re: Postback Implementation
Posted: Mon Oct 26, 2009 4:34 pm
by Christopher
Not only that, in this style there is, if anything, more code in the templates -- you just hide it from yourself while adding a bunch of overhead.
Re: Postback Implementation
Posted: Tue Oct 27, 2009 12:28 am
by JNettles
I would completely disagree with this, however, I won't go there in light of derailing this thread

In terms of the goal of this project. The idea is to have templates that can be easily edited via the markup specialists w/o them knowing a lick of PHP (or even knowing a special markup syntax, ala Smarty). I'm favoring development benefits over raw speed in this project.
Re: Postback Implementation
Posted: Tue Oct 27, 2009 1:44 am
by Christopher
JNettles wrote:In terms of the goal of this project. The idea is to have templates that can be easily edited via the markup specialists w/o them knowing a lick of PHP (or even knowing a special markup syntax, ala Smarty). I'm favoring development benefits over raw speed in this project.
I think that is certainly a reasonable goal. I often use simple HTML templates for both non-technical and untrusted users.
I think my first question would be -- Is there already a template system that does this? Especially one that is standalone, rather than tied into a framework.
If not then I think this system would have two layers. The lower layer would be some kind of system that has PHP code and/or conventions on the server side to process requests and create responses. And to work with this would be Javascript code and/or conventions on the client side to generate the requests to and display the responses from the server. I see no reason why you could not code these templates directly in Javascript/HTML, or have a PHP library that would generate the Javascript/HTML.
The upper layer is a template library that would parse templates and generate the Javascript/HTML that is actually sent to the browser. This would allow "markup specialists" to create templates that would in turn work with the lower layer.
Are there standards for this markup, such as what .NET uses?
Re: Postback Implementation
Posted: Tue Oct 27, 2009 2:24 pm
by JNettles
That's pretty close to where this is aiming. I'm sure that there are .NET specifications available as they were made public several years ago but I haven't gone looking for them. Right now it gets handled like this (order of operations)
1. Controller receives a page request and logs all incoming data (ie: POST)
2. Controller loads appropriate markup file into memory
3. Controller loads appropriate code-behind file - each page is its own individual class with public functions detailing events.
4. Parses markup. Any markup seen as <jar:SomeCustomControl id="example1".../> points at a class file which generates HTML markup and any necessary Javascript.
5. Page specific onload event is run.
6. Control onload events are run (any object in the markup which has an ID attribute is represented as a control).
7. Page specific PageComplete event is run. Controls are referenced as objects in the class definition: $this->textbox1->value = "cheese";.
8. DOM is reassembled with all custom controls turned into HTML blocks; changes are committed - page is rendered.
9. A postrender event is fired.
I intend to have a more specific page life-cycle implemented soon but at the moment it runs similar to this. This is all very .NET in implementation and is based off of some of the things Prado has done.
Re: Postback Implementation
Posted: Tue Oct 27, 2009 4:46 pm
by Christopher
- What are you using for your Javascript library?
- Do you have a simple example of what the HTML/Javascript that gets sent to the browser would look like?
- How do you deal with the need for server side validation, security, etc.?