Problem referencing variables in objects
- From: "Rob Dorn" <r.dorn@xxxxxxxxx>
- Date: Mon, 22 May 2006 22:55:21 +0200
Hello all.
I have an urgent problem building a small form processing system.and hope
somebody out
there can help me?
I have a form class which contains severals elements of the type input text
(created by the
TextInput class). These element classes are added to the $_elements array
that acts as an
object stack (see pseudo code below).
The render() function of the form will loop through the $_elements stack and
calls the render()
functions of each element. This element render() function will return the
html and will finally
build the complete page.
This method workt fine, so I would like to do the same with the validate
function. This also work
as expected, except for one thing:
When the validation of a text input element failes I fill a class variable
called $_message. This
messages should be rendered (displayed) in the "div" element containing the
input text element.
However this is not the case. The message is set and known in the validate()
function but not in
the render() function which is called some time later.
So what am I doing wrong? Is this a problem of the variable scope, or the
wrong way to reference
objects or variables? Can somebody please give me hint?
class Form
{
var $_elements = array();
function render()
{
// render every element in the form $_elements array (return the html
sting)
}
function validate()
{
// call the validate() function of every element in the form $_elements
array
}
}
class TextInput
{
var $_message;
function render()
{
// render this element (return the html sting)
// if a $_message is set (by the validate function) render it into the
html output
}
function validate()
{
// see if the value of this element is valid; if not set the $_message
variable
}
}
.
- Follow-Ups:
- Re: Problem referencing variables in objects
- From: George Mills
- Re: Problem referencing variables in objects
- Prev by Date: Re: Is it A MUST to have internet to install mySql database?
- Next by Date: Re: Problem referencing variables in objects
- Previous by thread: To send mail for php...
- Next by thread: Re: Problem referencing variables in objects
- Index(es):
Relevant Pages
|