|
Posted by Ramon on 06/14/06 09:44
Thanks Rik,
this does work.
I'm sorry that I keep asking, but I'm trying to understand this.
I wonder if this is the correct way to address the $m_oTextBoxes array.
That array should be treated as if it were private, I suppose..?
Actually, I should have an interface method to call this array:
class HTMLForm {
var $m_oTextBoxes = array();
// Added method: ========================================
function getTextBoxByID($sID) {
return This->m_oTextBoxes[$sID];
}
// ======================================================
function addTextBox($oTextBox) {
$this->m_oTextBoxes[$oTextBox->getID()] = $oTextBox;
}
}
Then, I still have the question how to call the right instance of the
TextBox-class's getOuterHTML method.
Because this will not work here: echo
$oForm->m_oTextBoxes["Nr"]->getOuterHTML();
Thanks for your patience!
Ramon.
?>
"Rik" <luiheidsgoeroe@hotmail.com> wrote in message
news:581f9$448fd547$8259c69c$14103@news1.tudelft.nl...
> Ramon wrote:
>> This is my code (in short):
>
>> function getOuterHTML () {
>> return "<input type='text' name='" . $this->m_sName . "'
>> value=' . $this->m_sValue . '>";
>> {
>
>
> I assume the { is } in your actual code?
>
> Try this:
>
> <?
> class TextBox {
> var $m_sID;
> var $m_sName;
> var $m_sValue;
>
> // Class Constructor:
> function TextBox ($sID, $sName, $sValue) {
> $this->m_sID = $sID;
> $this->m_sName = $sName;
> $this->m_sValue = $sValue;
> }
>
> function getID() {
> return $this->m_sID;
> }
>
> function getOuterHTML(){
> return "<input type='text' name='$this->m_sName'
> value='$this->m_sValue'>";
> }
>
> }
>
> class HTMLForm {
> var $m_oTextBoxes = array();
>
> function addTextBox($oTextBox) {
> $this->m_oTextBoxes[$oTextBox->getID()] = $oTextBox;
> }
> }
>
> $oTxtNumber = new TextBox ("Nr", "Number", "123");
> $oForm = new HTMLForm;
> $oForm->addTextBox($oTxtNumber);
> echo $oForm->m_oTextBoxes["Nr"]->getOuterHTML();
> ?>
>
> Works fine in PHP4 here.
>
> Grtz,
> --
> Rik Wasmus
>
>
Navigation:
[Reply to this message]
|