Persistent Objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

At work we use Java so one thing is annoying me. Is there really no
way to create a persistent object in PHP?  As far as my understanding
goes each object will be recreated on each and every request.

The reason I was asking is I wanted to create a form object that would
be used as follows.

which would require recreating the from stuff three times at least
Once for a JS file. Once for a HTML output.  And once for Server side
validation)

Please note that the following is just an example off the top of my
head the code to do this hasn't been written yet and the exact
implemantation may be different.  It would be much better to only
create the object once.

<?php
...
Other stuff goes here.
...
//Create a new form
formReg = new Form ("registration");

regStyle = new RenderStyle(HTML_AND_JAVASCRIPT_TABLELESS);
formReg->setRenderStyle();

/**
* Set the username field and its Validation
*/
fieldUsername = new Field("username");
fieldUsername->setLabel("User Name");
fieldUsername->setType(FIELD_TEXT);
fieldUsername->setCompulsary(true);
fieldUsername->setUnique(true);
fieldUsername->setMinLength(6);
fieldUsername->setMaxLength(20);
fieldUsername->setMaxLengthError(fieldUsername->getMinLengthError());
fieldUsername->setValidCharachters(CHARACHTERS_A-Z_1-9);

formReg->addField(fieldUsername)
.....
//OTHER FIELD STUFF HERE
.....

//Adds the link to a generated JS file at the top;
if (frmReg->needsJSCode == true) {
 output->add(formReg->getJSValidationURL)
}
....
//CONTINUE WITH THE REST OF THE HTML PAGE
....

//Insert the form into the HTML
output->add(fromReg->getForm(regForm));
?>

In the custom JS file we need;
<?php
frmReg->getValidationAsJavascript()
?>

Then after this in the page that receives the form submission we again
need to get the validation rules which means recreating the the form
object at least three times.  This time to validate serverside.

<?php
session_start() {
....
if (!frmReg->validates)  {
 $_SESSION[VALIDATION_ERROR] = frmReg->getValidationError();
 $_SESSION[ERROR_FIELD] = frmReg->getValidationField();
...
//logging goes here
...
 HttpResponse::redirect ( REGISTRATION_URL) ;
....
} else {
...
 // Attempt to save to the DB
 // Redirect on error

 // log a successfull registration
...
 require_once (REGISTRAION_SUCCESS_PAGE);
}

?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux