|
Posted by David Haynes on 11/03/05 13:44
Mark ??;-) wrote:
>> When you say you have encapsulated the files as an object, does this mean
>> that you have a file object or that you have objects that access files? In
>> the first example, you would have generic methods (read, write, delete,
>> create) that concerned all files as a generic type. In the second example,
>> file access would simply be a product of satisfying a method on an object.
>
> I have file objects. Basically I have a form that gets input from a user
> including things like date, time, section, and the selected file. I am
> considering this my file object, which I will then upload, display, or
> delete. Maybe I need to create different objects to deal with the display
> portion, I don't know.
I think you are confusing the file object concept with the file instance
concept. When the user fills in your object - either via the constructor
or via setter methods on it - it is dealing with an instance of the
object. The instance should be able to produce an HTML representation of
itself in just the same way it could product a regular text
representation of itself with, say, var_dump().
So, let's say your file uses setter methods. Your code for file would
look something like this when used as an instance:
$file = new File();
$file->setDate('2005-11-03');
$file->setTime('06:35:27');
$file->setPath('c:\foo');
Then when you wanted to express this instance of the object File as
HTML, you would use the toHTML() method (or build the HTML via getter
methods). For example:
<body>
<h1>Your File</h1>
<?php $file->toHTML() ?>
</body>
In your File object, you would have something like the following:
class File {
private $date = null;
private $time = null;
private $path = null;
function setDate($date) {
$this->date = $date;
}
// other setters
function toHTML() {
return "<table border=\"0\">"
"<tr>"
"<th>Date:</th><td>$this->date</td>"
"<th>Time:</th><td>$this->time</td>"
"<th>Location:</th><td>$this->path</td>"
"</tr>"
"</table>";
}
}
Note: I would probably add $date, $time and $path to the constructor
since that information seems to always be required for an instance of File.
>
> On a slight tangent..the file information form consists of several <select>
> lists which allow users to select the day, month, year, etc. I've have
> tried turning this group of selects into a class, but I am having problems
> with the array of values. If I post the code would someone be able to guide
> me through the process of converting this group of functions into a class?
Email me a copy and I'll take a look. (davidDOThaynes2ATsympaticoDOTca)
-david-
Navigation:
[Reply to this message]
|