Intro
I really must admit that I understand every example code I see in the tutorials on references, but using it myself is hard every time again, thus I have been avoiding them as much as possible.
Now I have found that it is time to use them right, in my new project: a document management system.
My problem
I have a class called 'Folder' which has a name and filepath (location). All folders have a parent, except the root folder (where parent is null).
The idea is to make a class 'Document' later, which holds a reference to a Folder, in order to locate it. If I want to move the document, I only have to change the reference.
I am a bit in the dark on how to organise and traverse these directories (do they need a coordinating class maybe?).
My current implementation is small, very small:
I don't want to keep the printCode there, it will go to another class later, but is there for testing now.PHP Code:<?php
/**
* ONADMS - Oh, Not Another Document Management System
*
* @author Y. Janse
* @version $Revision$
* @copyright 2004
* @package ONADMS
* $Id$
*/
/**
* Folder class.<br/>
* Folder container object in FileSystem
* @package ONADMS
*/
class Folder {
var $parent;
var $name;
var $location;
function Folder(&$parent = null, $name, $location)
{
$this->parent =& $parent;
$this->name = $name;
$this->location = $location;
}
function getName()
{
return $this->name;
}
function & getParent()
{
if($this->parent != null) {
return $this->parent;
} else {
return false;
}
}
function setParent(&$parent)
{
$this->parent &= $parent;
}
function printInfo()
{
echo 'I am ' . $this->name . '<br/>';
echo 'I live in ' . $location;
if($this->parent == null) {
echo ' by myself.<br/>';
} else {
echo ' with my mommy ' . $this->parent->getName() . '<br/>';
}
}
}
?>
I test this class using the following:
Now I thought I was doing it right, but Xdebug disagrees:PHP Code:<?php
require_once('lib/FileSystem/class.Folder.php');
$f1 =& new Folder(null, 'Documents', '/documents');
$f2 =& new Folder($f1, 'Reports', '/documents/reports');
$f3 =& new Folder($f2, 'Finance', '/document/finance');
$f1->printInfo();
$f2->printInfo();
$f3->printInfo();
?>
Who can help me with this problem, and perhaps advise me on how to organise the Folders, maybe in a container of some kind?Code:Parse error: parse error, unexpected '=', expecting ')' in c:\inetpub\wwwroot\onadms\lib\FileSystem\class.Folder.php on line 21 Call Stack # Function Location 1 {main}() c:\inetpub\wwwroot\onadms\ignore.php:0 Fatal error: Cannot instantiate non-existent class: folder in c:\inetpub\wwwroot\onadms\ignore.php on line 4 Call Stack # Function Location 1 {main}() c:\inetpub\wwwroot\onadms\ignore.php:0
Thanks a heap in advance!





Bookmarks