"Mike Smith" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I am starting to get a handle (I think) on OOP. I was wondering if
> anyone would care to comment on what I think I understand:
>
> For simplicity's sake class.php contains AddItem() and DisplayItems().
> Since submitting form data
>
> <?php
> include('class.php');
>
> If(!$_POST['submit']){ //Do I need to instantiate(?) $po everytime the
> page reloads?
> $po = new PO;
> }
If you instantiate on every page load, you will only have one item - the
last one added. So, you will need to instantiate only once, and then store
the object in a session variable - but beware! Assigning the local variable
to the object will make a copy of the object stored in the session, so you
will have to either
1). Set the session variable back to $po at the end of the page, as such:
$_SESSION[po] = $po;
or
2). Set the local variable via reference to the session variable when
initializing $po at the beginning of the page (which references the existing
object, and does NOT make a copy), as such:
$po = &$_SESSION[po]; // notice the & which sets $po by
reference, rather than making a copy.
>
>
> If($_POST['submit']){
> $po->AddItem();
> }
>
> <form action="$PHP_SELF" method="POST" >
> ...form fields and a submit button...
> </form>
>
> $po->DisplayItems();
>
> ?>
>
> Is this a good basic methodology (aside from checking the form fields
> for valid characters).
>
> Thanks,
> Mike Smith
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php